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.

- 2,397
- 6
- 35
- 39

- 1,044
- 4
- 14
- 28
11 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

- 19,888
- 10
- 61
- 114

- 2,153
- 19
- 31
-
2Legend! Been looking for a way to do this for so long – kingraam Jul 30 '12 at 13:39
-
1@sstn can you elaborate? Is there a better solution for 5.0? – Daniel Wilson Nov 28 '14 at 18:22
-
2@DanielWilson My workaround now is to set the divider to null and explicitly inserting dividers into the dataset for the adapter (at least virtually). It is quite ugly, as you need another view type, indices for your real data change etc. I believe this is the change in the source tree which changed the behaviour: https://android.googlesource.com/platform/frameworks/base/+/20cc605b69a017316112929666255226c184a376%5E!/#F0 – sstn Dec 01 '14 at 08:54
-
4Wow, that is some serious flag hell going on there. Why do they think we dont want dividers between disabled items? Seems like it should at least be an option. And it should default to showing them. – Greg Ennis Feb 06 '15 at 18:34
-
Also with this approach, a disabled item can still be clicked using a hardware keyboard (or emulator). Use the arrow keys to bring it into focus, then hit enter. – Daniel Lubarov May 11 '15 at 22:03
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.

- 338
- 4
- 9
This worked for me. This will show the divider as well as disable the click on list item. Even in Android 5.0.
Set this on the list item
android:focusable="true"
android:clickable="false"
Setting just clickable to 'false' didn't work for me. And Overriding isEnabled() caused the above mentioned issue of hiding the divider in 5.0.
And my ListView looks like this.
<ListView
android:id="@+id/lvItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@color/Gray"
android:dividerHeight="1px">
</ListView>
No android:listSelector="@android:color/transparent"
needed here

- 150
- 2
- 11
All of the solutions above have a problem with compatibility (works nice on one version of Android, but fails on other) - especially if you want to use transparency. The only really robust solution is to use nine-patch file.
You can download from: http://ge.tt/517ZIFC2/v/1?c
Just place the chosen png to the drawable-nodpi
directory to avoid resampling.
And use it in your Adapter:
convertView.setBackgroundResource(R.drawable.border_b1px_black);

- 1,578
- 2
- 19
- 34
You will have to enable the rows in the isEnabled() method for Android 5.0 and higher.
But you can still disable the rows another way:
In the following example, I'm disabling every row but row 0:
In your getView method for your Adapter:
if (position > 0) {
convertView.setClickable(true);
}
For some reason setting clickable to true disables the row. I'm not sure why. I assumed at first this would make it clickable but it doesn't.
Reference: Android ListView child View setEnabled() and setClickable() do nothing
See user622689 answer.
-
you'd want to make sure you set clickable to false in an else statement - otherwise random list items wouldn't be clickable because of view recycling – starkej2 Aug 10 '15 at 18:30
Instead of setting isEnabled
, on your ListView
, set android:listSelector="@android:color/transparent"
as well as android:focusable="true"
and
android:clickable="true"
. It gives the same effect

- 1,809
- 1
- 22
- 37
-
I find this is the best workaround since you do not need to add extra code to modify your list items. If you have an item click listener on your listview for some items you will need to add defensive code there for ignoring the clicks on disabled items but that's it. – androidseb Feb 03 '16 at 15:40
I can verify that when areAllItemsEnabled()
returns false, then for every specific row that you want to set as non-selectable via isEnabled(int position)
the line separator (divider) disappears. Setting areAllItemsEnabled()
to always return true, and playing just with isEnabled(int position)
should make specific rows non-selectable with the divider showing just fine.

- 8,440
- 5
- 49
- 69

- 21
- 3
I had the same problem on Lollipop. Workaround for me was to change the background in the listview to transparent. In my case I was missing the dividers on the nav drawer on rows where isEnabled
returns false when I set a background to a color. Try something like:
android:background="@android:color/transparent"

- 1
I had a similar problem. I solved it by explicitly setting the divider height of the list view to be "1dp"
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="1dp"
/>

- 1,063
- 1
- 11
- 18
use setDivider(Drawable divider)
method of the listview

- 10,258
- 5
- 70
- 83
-
Thanks for the answer. I tried to set the divider but the problem still retains. I found out that the divider disapears when the methods ArrayAdapter.areAllItemsEnabled() and ArrayAdapter.isEnabled() both returns "false". Do you have any ideas, how to solve my problem. Thanks in advance. – saric Mar 30 '11 at 08:23
To actually EMULATE a disabled item, in the getView of the adapter, where layout = (your return value)
:
if ( ! YOUR_ITEM_REF?.isEnabled()) {
layout.setClickable(true);
layout.setAlpha(0.5f);
} else {
layout.setClickable(false);
layout.setAlpha(1f);
}
This 100% works the way you would think it should, by simply disabling the item, and painting it as disabled by using a simple alpha filter to get the 'Ghost' effect.
Where YOUR_ITEM_REF is your object (item) in the list, not the adapter or the list, but the actual item.
Your adapter should return true for allItemsEnabled
and isEnabled
, to disable the broken default feature handling.
This is how i fixed my problem, using the answer given by Sandy D.
.
This does not work if your layout
has a click handler set (which is not likely, but could happen through user error).

- 462
- 5
- 13
-
if you are not using the convertView, and creating new views everytime, you don't need the else block. – Hypersoft Systems Oct 18 '19 at 05:08