1

After disabling certain items in the listview, the divider disappears. How do I make my divider visible?

For reference, I found that the solution says override the areAllItemsEnabled of the adapter and return true. But It doesn't work.

@Override
  public boolean isEnabled(int position) {
    if (position == 1) {
      return false;
    }
    return true;
  }

  @Override
  public boolean areAllItemsEnabled() {
    return true;
  }

My ListView is just like below.

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:fastScrollEnabled="true"
    android:horizontalSpacing="@dimen/list_item_padding_horizontal"
    android:listSelector="@drawable/default_list_item_selector"
    android:scrollbars="vertical"
    android:stretchMode="columnWidth"
    android:verticalSpacing="@dimen/list_item_padding_vertical" />

Please help me.

yong
  • 83
  • 1
  • 8
  • can you add a screenshot on your question ? – John Joe Mar 07 '19 at 08:10
  • This link is exactly the same question, and no solution helps. https://stackoverflow.com/questions/5375138/disappearing-divider-in-listview-when-arrayadapter-isenabled-returns-false – yong Mar 07 '19 at 23:23
  • I can not upload a file because of a firewall. In addition, for example, when disabling the second item, the divider of the second item disappears. – yong Mar 08 '19 at 00:29

1 Answers1

1

Best option you can add in item_row layout, easily you can customize as per your requirment. Like below :

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"
>

 <TextView
      android:layout_width="wrap_content"
      android:layout_centerVertical="true"
      android:gravity="center"
      android:text="Title"
      android:textColor="@color/black"
  />

   <View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:background="@color/grey"
   />

</LinearLayout>

View is worked as a divider/Separate line .

Hkh
  • 357
  • 1
  • 10