How to create a drop-down list in the navigation box (in Android)?

I would like to create a navigation box with several extensible, selectable elements and some non-extensible elements. The StackOverflow consensus for questions similar to mine points to ExpandableListView solutions (which may not even apply to my idea). For the most part, what people are asking for is a way to split items in a Nav box, like a GMail shortcut application, not what I'm trying to do ...

... which is mostly outlined HERE enter image description here

and LOOK HERE (although all, but not some of them), And not , for example THIS IS ANSWER .

+7
android android-fragments expandablelistview navigation-drawer
source share
2 answers

Use ExpandableListView in DrawerLayout, for example:

 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout2" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tv_commentary_behind_nav" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|top" android:text="Frame text" /> </FrameLayout> <!-- The navigation drawer --> <ExpandableListView android:id="@+id/left_drawer2" android:layout_width="250dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/white" android:choiceMode="multipleChoice" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> 

Then initialize the code as follows:

  private DrawerLayout drawer; private ExpandableListView drawerList; private CheckBox checkBox; private ActionBarDrawerToggle actionBarDrawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.drawer_layout); drawer = (DrawerLayout) findViewById(R.id.drawer_layout2); drawerList = (ExpandableListView) findViewById(R.id.left_drawer2); drawerList.setAdapter(new NewAdapter(this, groupItem, childItem)); } 
+1
source share

You must have a class that has all the implemented ExpandableListAdapter methods, as well as the ChildItemsInfo class and the GroupItemsInfo class, while MainActivity has click listeners for grouping elements and their children

... now more specifically ...

You can put this in getGroupView() inside the MyExpandableListAdapter class

  View ind = convertView.findViewById(R.id.group_indicator); View ind2 = convertView.findViewById(R.id.group_indicator2); if (ind != null) { ImageView indicator = (ImageView) ind; if (getChildrenCount(groupPosition) == 0) { indicator.setVisibility(View.INVISIBLE); } else { indicator.setVisibility(View.VISIBLE); int stateSetIndex = (isExpanded ? 1 : 0); /*toggles down button to change upwards when list has expanded*/ if(stateSetIndex == 1){ ind.setVisibility(View.INVISIBLE); ind2.setVisibility(View.VISIBLE); Drawable drawable = indicator.getDrawable(); drawable.setState(GROUP_STATE_SETS[stateSetIndex]); } else if(stateSetIndex == 0){ ind.setVisibility(View.VISIBLE); ind2.setVisibility(View.INVISIBLE); Drawable drawable = indicator.getDrawable(); drawable.setState(GROUP_STATE_SETS[stateSetIndex]); } } } 

... and as for the layout view, here is what my group_items.xml looks like

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/group_heading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingTop="16dp" android:paddingBottom="16dp" android:textSize="15sp" android:textStyle="bold"/> <ImageView android:id="@+id/group_indicator" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/arrow_down_float" android:layout_alignParentRight="true" android:paddingRight="20dp" android:paddingTop="20dp"/> <ImageView android:id="@+id/group_indicator2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/arrow_up_float" android:layout_alignParentRight="true" android:visibility="gone" android:paddingRight="20dp" android:paddingTop="20dp"/> 

Fuzzy enough ?, comment when

+1
source share

All Articles