Petar-Krešimir Petar-Krešimir - 1 month ago 10
Android Question

AppCompact ListView CAB not showing

I am trying to make my listview use multiple select feature. I have followed a couple of tutorials and came up with the code below. For some reason I can't get the CAB to show and I'm wondering what am I doing wrong here.

This is the function in which I try to set the listview multi selectable and where I try to inflate the CAB

public void loadGroupSchedule(final int gid) {
SUBLEVEL = 1;
CustomListViewValuesArrSchedules.clear();
// list.notify();
list = (ListView) findViewById(R.id.listViewCustom);
list.setAdapter(null);

list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

list.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {

}

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.test, menu);
return true;
}

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}

@Override
public void onDestroyActionMode(ActionMode mode) {

}
});

RequestQueue queue = Volley.newRequestQueue(this);
StringRequest sr = new StringRequest(Request.Method.POST, SERVER_SCHEDULES, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
... //too much code, deleted it from here
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (SUBLEVEL != 5) {
hideLoading();
list.setVisibility(View.INVISIBLE);
ISVU.setVisibility(View.INVISIBLE);
noInternet.setVisibility(View.VISIBLE);
Button retry = (Button) findViewById(R.id.noInternetBtn);

retry.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
noInternet.setVisibility(View.INVISIBLE);
list.setVisibility(View.VISIBLE);
loadGroupSchedule(gid);
}
});
}
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("groupid", String.valueOf(gid));

return params;
}

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
//params.put("Content-Type", "application/x-www-form-urlencoded");
return new HashMap<String, String>();
}
};
showLoading();
queue.add(sr);

}


This is my listview item layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:id="@+id/classItemLV"
android:background="@drawable/list_row"
android:minHeight="80dp"
android:elevation="2dp">

<RelativeLayout
android:layout_width="16dp"
android:layout_height="wrap_content"
android:id="@+id/lday"
android:layout_alignParentStart="true"
android:layout_marginStart="10dp"
android:layout_centerVertical="true"
android:background="@color/colorPrimary"
android:minWidth="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="P\nO\nN"
android:id="@+id/DAY1"
android:layout_alignParentStart="false"
android:textColor="#fff"
android:textSize="15sp"
android:layout_margin="2dp"
android:textAlignment="center"
android:layout_centerInParent="true" />

</RelativeLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lTime"
android:layout_alignWithParentIfMissing="false"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_toEndOf="@+id/lday">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="10"
android:id="@+id/timeFrom"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:textColor="@color/colorLV3Dark" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="12"
android:id="@+id/timeTo"
android:textColor="@color/colorLV3Dark"
android:layout_below="@+id/timeFrom" />
</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lInfo"
android:layout_marginStart="10dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/lTime">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Analiza financijskih izvještaja"
android:id="@+id/className"
android:textColor="@color/colorLV3Dark"
android:layout_alignParentStart="true"
android:layout_marginEnd="10dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="prof. dr. sc. Ivan Ivić"
android:id="@+id/classTutor"
android:textColor="@color/colorLV3"
android:layout_below="@+id/className" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="PREDAVANJE - DV41"
android:id="@+id/classTypePlace"
android:textColor="@color/colorLV3"
android:textSize="12sp"
android:layout_below="@+id/classTutor" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Datum: 5.10.-25.1."
android:id="@+id/classDate"
android:textSize="12sp"
android:textColor="@color/colorLV3"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/classTypePlace"
android:layout_marginEnd="10dp" />
</RelativeLayout>

</RelativeLayout>


This is my listview

<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listViewCustom"
android:dividerHeight="0dp" />


And this is my menu

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/test_id"
android:title="test"
android:icon="@drawable/ic_chick" />
</menu>


I am using a custom adapter for the listview, could that be an issue? Any help would be greatly appreciated.

Answer

Maybe, the listener can not call an action mode in the Toolbar.
Read this topic to call it manually.