0

I have many navigation drawers (mostly in Google Apps) where few of the items are having no List item seperators, while some list items are having list seperators. I want to achieve the same functionality for my app.

can anybody please help me understand the implementation? How can i hide list seperator for few of the list items while others have it?

regards,

Rajan

Rajan M
  • 5
  • 2
  • Use a listview with different layouts for each row. Making some rows separators: http://stackoverflow.com/questions/4777272/android-listview-with-different-layout-for-each-row – VM4 Oct 19 '14 at 10:49

1 Answers1

1

For each list item row use this layout:

<LinearLayout>
    (...)
    <View
    android:id="@+id/viewSeparator1"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="#646464"/>
</LinearLayout>

Then on your adapter use this

public class DrawerListAdapter extends BaseAdapter{

    (...)

    public View getView(int position, View convertView, ViewGroup parent){
        (...)
        View mViewSeparator = convertView.findViewByID(R.id.viewSeparator1);

        //I dont know when you want to show a separator so replace this line with the apropriate check: for example: if(position == 0) etc
        if(hasSeparator)
            mViewSeparator.setVisibility(View.VISIBLE);
        else
            mViewSeparator.setVisibility(View.GONE);

        return convertView;
    }
}
nunoh123
  • 1,087
  • 1
  • 10
  • 17
  • Dont forget to remove the default separator from the listview since you are providing a separator for each row: use: android:divider="@null" or yourListView.setDivider(null); – nunoh123 Oct 19 '14 at 12:16
  • Thanks for your reply. But i could not get how to evaluate it for each list item. Currently I am applying adapter like this 'code' adapter = new DrawerListAdapter(getApplicationContext(), navDrawerItems); mDrawerList.setAdapter(adapter);'code' . How can i apply the above code in my case. – Rajan M Oct 19 '14 at 13:52
  • Edited answer: The code i gave you needs to be inside getView from your custom adapter class – nunoh123 Oct 19 '14 at 14:21