Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disappearing divider in ListView when ArrayAdapter.isEnabled returns false

I'm using ListActivity with my own ArrayAdapter class. When I override the methods ArrayAdapter.areAllItemsEnabled() and ArrayAdapter.isEnabled() the divider between some cells in the list view disappear. Does anyone know how to avoid this? I need the dividers to display even for disabled cells.

like image 892
saric Avatar asked Mar 21 '11 08:03

saric


2 Answers

Return true in areAllItemsEnabled() and false in isEnabled for specific item. The disabled item wont be clickable but you will still be able to view the divider lines

Note: This doesn't work for Android 5

like image 157
Alok Kulkarni Avatar answered Sep 19 '22 12:09

Alok Kulkarni


You can essentially disable a list item by giving any one of its elements the following properties.

android:focusable="true" android:clickable="true" 

So the following list item layout will not be clickable, but will show dividers, without the need to implement areAllItemsEnabled() or isEnabled(int position).

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:focusable="true"     android:clickable="true">     <TextView         android:text="Large Text"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/> </LinearLayout> 

This may help in Android 5.0 where the original answer no longer seems to work.

like image 31
tom-pratt Avatar answered Sep 18 '22 12:09

tom-pratt