ListView CAB not showing up on Long click

179 views Asked by At

I am using a custom array adapter and layout for my view. Custom view's List items have different buttons in it which are working without any issues. However, I want to select each List Item and have CAB appear when long pressed. For some reason CAB doesn't appear when I am using it with my custom view. However, if I uncomment the line to use String Array adapter then it works fine.

String[] ITEMS = new String[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6" };    
datasource = new FavoritesDataSource(this);
datasource.open();
tempList = datasource.getAllFavorites();
myAdapter = new FavoritesArrayAdapter(this, tempList);
datasource.close();

ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
lv.setMultiChoiceModeListener(new ModeCallback());

setListAdapter(myAdapter);
//setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, ITEMS));

I am not sure what I am doing wrong. Any help will be appreciated. Thanks

1

There are 1 answers

0
programmerboy On

After many hours of debugging the problem came out to be really simple. When using Custom Adapter with your custom list view with clickable buttons inside it, list view disables its ability to click the Parent ListView Item and that causes the Parent ListView Item not to be selected or clicked. In your custom_list_view_item.xml you need to add this attribute to the parent view

android:descendantFocusability="blocksDescendants"

This will allow Parent ListView Item to be clickable and you can click child items in your ListView Item too. Hope it helps.