7

मैं एक नेविगेशन ड्रॉवर बनाने में सक्षम होना चाहता हूं जिसमें कुछ विस्तारणीय, चयन करने योग्य आइटम और कुछ गैर-विस्तारणीय आइटम हैं। ExpandableListView (जो मेरे विचार पर भी लागू नहीं हो सकता है) द्वारा समाधान के लिए मेरे बिंदु के समान प्रश्नों के लिए स्टैक ओवरव्लो पर सर्वसम्मति। अधिकांश भाग के लिए, लोग क्या पूछ रहे हैं, एनवी ड्रॉवर में वस्तुओं को अलग करने का एक तरीका है जैसे जीमेल ऐप लेबल के साथ करता है, न कि मैं क्या करने की कोशिश कर रहा हूं ...नेविगेशन ड्रॉवर (एंड्रॉइड में) के भीतर ड्रॉपडाउन कैसे बनाएं?

... जो अनिवार्य रूप से उल्लिखित है HERE enter image description here

और SIMILARLY HERE (though all, not some are dropdowns) । और THIS ANSWER की तरह नहीं।

उत्तर

1

एक DrawerLayout के भीतर एक ExpandableListView उपयोग करें, ताकि जैसे:

<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> 

फिर तो जैसे कोड में प्रारंभ:

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

'groupItem' और' childItem' क्या हैं। न्यूएडाप्टर क्या है और यह कुछ आइटमों को विस्तार योग्य बनाने के लिए 'groupItem' और' childItem' को कैसे संभालता है? आपका जवाब अधूरा है। –

+0

groupItem समूह विकल्पों में से प्रत्येक के लिए स्ट्रिंग युक्त एक सरणी है। उपरोक्त ग्राफिक में "टॉप व्यू 2"। childItem एक मैट्रिक्स/हैशैप है जिसमें प्रत्येक समूह आइटम का चयन करने के बाद आइटमों की एक सूची शामिल है। NewAdapter समूह आइटम्स और childItem डेटासेट के मानों को प्रत्येक आइटम के धारक को फुलाते समय देखता है। – AlleyOOP

1

आप एक वर्ग ExpandableListAdapter के सभी लागू किया तरीकों होने के साथ ही होना चाहिए ChildItemsInfo कक्षा और GroupItemsInfo कक्षा, MainActivity के साथ समूह आइटम और उनके बच्चों को क्लिक श्रोताओं के साथ

... अब और अधिक विशिष्ट होना ...

आप है कि अंदर getGroupView() के भीतर इस जगह कर सकते हैं MyExpandableListAdapter वर्ग

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]); 
      } 
     } 
    } 

... और लेआउट दृश्य के लिए के रूप में, यह कैसे मेरे group_items है। एक्सएमएल

<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"/> 

पर्याप्त स्पष्ट प्रतीत होता है ?, टिप्पणी जब भी

संबंधित मुद्दे