9

मैं अपने जीवन के लिए यह नहीं समझ सकता कि मेरा विस्तारणीय लिस्ट व्यू क्यों विस्तार नहीं करता है ... मैंने विस्तारित लिस्ट व्यू के लिए केवल हर क्लिक श्रोता में लॉग स्टेटमेंट का उपयोग किया है और ऐसा लगता है कि उनमें से किसी को भी बुलाया नहीं जाता है।एंड्रॉइड विस्तार योग्य सूचीदृश्य विस्तारित घटनाओं का विस्तार या प्राप्त नहीं करता है

मुझे पता है कि इस विषय पर कई पोस्ट हैं लेकिन मैंने उन सभी के माध्यम से पढ़ा है और कई चीजों की कोशिश की है और मुझे कोई भाग्य नहीं है, उम्मीद है कि मुझे कुछ छोटी त्रुटि याद आ रही है जो किसी और के लिए स्पॉट करना आसान होगा।

मुख्य गतिविधि:

public class ForumListActivity extends Activity { 

    private static ArrayList<Forum> forumList; 
    private static ArrayList<ArrayList<SubForum>> subForumList; 
    private ExpandableListView forumListView; 
    private ForumListAdapter forumListAdapter; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     this.setContentView(R.layout.main_page); 
     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

     forumListView = (ExpandableListView) this.findViewById(R.id.main_page_forum_list); 

     forumList = new ArrayList<Forum>(); 
     subForumList = new ArrayList<ArrayList<SubForum>>(); 
     setUpForums(this); 

     forumListAdapter = new ForumListAdapter(this, forumList, subForumList); 
     forumListView.setAdapter(forumListAdapter); 

     forumListView.setOnGroupExpandListener(new OnGroupExpandListener(){ 
      @Override 
      public void onGroupExpand(int groupPosition) { 
       Log.d("onGroupExpand", "this works?"); 
       for(int i=0; i<forumListAdapter.getGroupCount(); i++) { 
        if(i != groupPosition) 
         forumListView.collapseGroup(groupPosition); 
       } 
      } 
     }); 

     forumListView.setOnGroupClickListener(new OnGroupClickListener() { 
      @Override 
      public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { 
       Log.d("onGroupClick:", "worked"); 
       parent.expandGroup(groupPosition); 
       return true; 
      } 
     }); 
    } 

नोट: विधि setUpForums() बस प्रणाली सरणियों लेता है और उन्हें forumList और subForumList

ListViewAdapter में कहते हैं:

public class ForumListAdapter extends BaseExpandableListAdapter { 

    private ArrayList<Forum> groups; 
    private ArrayList<ArrayList<SubForum>> children; 
    private Context ctx; 

    public ForumListAdapter(Context ctx, ArrayList<Forum> groups, ArrayList<ArrayList<SubForum>> children) { 
     this.ctx = ctx; 
     this.groups = groups; 
     this.children = children; 
    } 



    @Override 
    public Object getChild(int groupPosition, int childPosition) { 
     return children.get(groupPosition).get(childPosition); 
    } 



    @Override 
    public long getChildId(int groupPosition, int childPosition) { 
     return childPosition; 
    } 



    @Override 
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      LayoutInflater inflater = LayoutInflater.from(ctx); 
      convertView = inflater.inflate(R.layout.forum_list_child_item_row, null); 
     } 

     SubForum currentSubForum = children.get(groupPosition).get(childPosition); 
     TextView name = (TextView)convertView.findViewById(R.id.child_row_forum_title); 
     TextView desc = (TextView)convertView.findViewById(R.id.child_row_forum_description); 

     if (name != null) 
      name.setText(currentSubForum.getName()); 

     if (desc != null) 
      desc.setText(currentSubForum.getDescription()); 

     convertView.setFocusableInTouchMode(true); 
     return convertView; 
    } 



    @Override 
    public int getChildrenCount(int groupPosition) { 
     return children.get(groupPosition).size(); 
    } 



    @Override 
    public Object getGroup(int groupPosition) { 
     return groups.get(groupPosition); 
    } 



    @Override 
    public int getGroupCount() { 
     return groups.size(); 
    } 



    @Override 
    public long getGroupId(int groupPosition) { 
     return groupPosition; 
    } 



    @Override 
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
     if (convertView == null) 
     { 
      LayoutInflater inflater = LayoutInflater.from(ctx); 
      convertView = inflater.inflate(R.layout.forum_list_group_item_row, null); 
     } 

     Forum currentForum = (Forum) groups.get(groupPosition); 
     TextView name = (TextView) convertView.findViewById(R.id.group_item_forum_title); 
     //ImageView image = (ImageView) convertView.findViewById(R.id.group_item_expander_image); 

     if(name != null) 
      name.setText(currentForum.getName());   

     /* 
     if(image != null) { 
      int[][] group_state_sets = {{}, {android.R.attr.state_expanded}}; 
      image.setVisibility(View.VISIBLE); 
      int stateSetIndex = (isExpanded ? 1 : 0) ; 
      Drawable drawable = image.getDrawable(); 
      drawable.setState(group_state_sets[stateSetIndex]); 
     } 
     */ 

     return convertView; 
    } 



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



    @Override 
    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 


} 

समूह लेआउट:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/turquoise_gradient" 
    android:orientation="horizontal" 
    android:paddingTop="6dip" 
    android:paddingBottom="6dip" 
    android:paddingLeft="6dip" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/turquoise_gradient" 
     android:orientation="vertical" 
     android:padding="2dip" > 

     <TextView 
      android:id="@+id/group_item_forum_title" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|left" 
      android:gravity="left" 
      android:paddingLeft="5dip" 
      android:textColor="@color/white" 
      android:textSize="16dip" /> 

    </LinearLayout> 

    <!-- 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:gravity="center|right"> 

     <ImageView 
      android:id="@+id/group_item_expander_image" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      android:gravity="center" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/collapse_down" /> 


    </LinearLayout> --> 

</LinearLayout> 

बच्चे लेआउट:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/turquoise_gradient" 
    android:orientation="horizontal" 
    android:paddingTop="6dip" 
    android:paddingBottom="6dip" 
    android:paddingLeft="6dip" > 


    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="2dip" 
     android:background="@drawable/turquoise_gradient" > 

     <TextView 
      android:id="@+id/child_row_forum_title" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:layout_gravity="center_vertical" 
      android:paddingLeft="5dip" 
      android:textColor="@color/white" 
      android:maxLines="1" 
      android:textSize="11dip" /> 

     <TextView 
      android:id="@+id/child_row_forum_description" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="left" 
      android:layout_gravity="center_vertical" 
      android:paddingLeft="15dip" 
      android:textColor="@color/white" 
      android:maxLines="2" 
      android:textSize="11dip" /> 

    </LinearLayout> 

</LinearLayout> 

मुख्य पेज लेआउट:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/black" 
    android:orientation="vertical" > 

    <ExpandableListView 
     android:id="@+id/main_page_forum_list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@color/black" 
     android:divider="@color/black" 
     android:dividerHeight="1dip" 
     android:clickable="true" /> 

</LinearLayout> 

किसी भी मदद प्रदान कर सकते हैं बहुत सराहना कर रहा है!

+0

अपने हो सकता है क्योंकि आप न वहाँ बच्चे डेटा है, यू डिबग – Rakshi

+0

कोशिश है टेक्स्टव्यू – Rakshi

उत्तर

21

मैंने आपके जैसी ही समस्या का सामना करना पड़ा। जांच के कुछ दिनों के बाद, मैंने पाया कि मैंने कुछ गलत किया है। इसलिए मैंने इसे छोटे बदलाव करके सही तरीके से काम करने के लिए तय किया।

में boolean onGroupClick(...) के शरीर को देखें।आप सच मतलब यह है कि "the click was handled"

आप लौटना चाहिए झूठी अगर आप का विस्तार करना चाहते लौटा दिया है। तो मैं सुझाव है कि आप इस तरह करना है:

forumListView.setOnGroupClickListener(new OnGroupClickListener() { 
    @Override 
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { 
      Log.d("onGroupClick:", "worked"); 
      parent.expandGroup(groupPosition); 
      return false; 
     } 
    }); 

android.widget.ExpandableListView कक्षा में, वहाँ एक विधि boolean handleItemClick(View v, int position, long id) जो विस्तार हो रहा/समूहों गिर सकती हैं या उचित बच्चे को क्लिक करने पर ही पारित करने के लिए जिम्मेदार है नामित है।

/* It's a group click, so pass on event */ 
     if (mOnGroupClickListener != null) { 
      if (mOnGroupClickListener.onGroupClick(this, v, 
        posMetadata.position.groupPos, id)) { 
       posMetadata.recycle(); 
       return true; 
      } 
     } 

    /* expanding/collapsing/other tasks... */ 

अगर आप को लागू onGroupClickवापसी सच को, 8 रेखा से नीचे कोड क्रियान्वित किया जा कभी नहीं होगा। (इसका मतलब है, समूह कभी नहीं ध्वस्त हो जाएंगे, विस्तारित)

आशा है कि मेरे उत्तर ने आपकी मदद की :-) शुभकामनाएँ!

+0

आपने अभी तक 3 दिनों के सिरदर्द बचाए हैं। एक महान उत्तर के लिए धन्यवाद और +1 –

+0

इसके लिए धन्यवाद! –

6

यदि u, chid के लिए किसी भी डेटा उपलब्ध है क्योंकि यदि u न किसी भी डेटा बच्चे बिल्कुल भी दिखाई नहीं होगा शायद तीन बातें यू जांच करनी है तो

  1. जांच कर रहे हैं।

2.Try को हटाने अगर लेआउट inflaters हालत की जांच आप का उपयोग करते समय

if (convertView == null) { 
    LayoutInflater inflater = LayoutInflater.from(ctx); 
    convertView = inflater.inflate(R.layout.forum_list_child_item_row, null); 
    } 
  1. आप भी Viewgroup यहाँ

    convertView = inflater.inflate(R.layout.forum_list_child_item_row,parent, false); 
    
पास करनी होगी
+0

के लिए अपने बच्चों के लेआउट में कुछ डिफ़ॉल्ट टेक्स्ट मान जोड़ना खराब डेटा मेरी समस्या थी, धन्यवाद फिर से !! –

0

अपनी गतिविधि में implements OnGroupExpandListener जोड़ें। फिर यह काम करेगा। मैं इसका उपयोग कर रहा हूं यह ठीक काम करता है।

0

जब आप विस्तारणीय सूचियों के साथ काम कर रहे हों तो समूह का विस्तार इसमें डिफ़ॉल्ट कार्यक्षमता है। मतलब यह है कि समूह में ही विस्तार है जब आप उस पर क्लिक करेंगे तो आप बस इस तरह अपनी सूची somthing में अपने डेटा को पॉप्युलेट onGroupExpand (पूर्णांक groupPosition) या किसी अन्य विधि overrirde करने की जरूरत है donot:

public class MyActivity extends Activity { 

    private ExpandableListView forumListView; 
    private ForumListAdapter forumListAdapter; 
    String[] forumList={"group 1","group 2","group 3"}; 
String[][] subForumList={{"group 1 child1","group 1 child1","group 1 child3"}, 
        {"group 2 child1","group 2 child2","group 2 child3"}, 
        {"group 3 child1","group 3 child2","group 3 child3"}, 
        }; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
this.setContentView(R.layout.main); 


forumListView = (ExpandableListView) this.findViewById(R.id.main_page_forum_list); 




forumListAdapter = new ForumListAdapter(this, forumList, subForumList); 
forumListView.setAdapter(forumListAdapter); 



    /* forumListView.setOnGroupExpandListener(new OnGroupExpandListener(){ 
    public void onGroupExpand(int groupPosition) { 
     Log.d("onGroupExpand", "this shit works?"); 
     for(int i=0; i<forumListAdapter.getGroupCount(); i++) { 
      if(i != groupPosition) 
       forumListView.collapseGroup(groupPosition); 
     } 
    } 
}); 

forumListView.setOnGroupClickListener(new OnGroupClickListener() { 
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { 
     Log.d("onGroupClick:", "worked"); 
     parent.expandGroup(groupPosition); 
     return true; 
    } 
});*/ 
    } 

    public class ForumListAdapter extends BaseExpandableListAdapter { 

     String[] groups; 
    String[][] children; 
    private Context ctx; 

    public ForumListAdapter(Context ctx, String[] groups, String[][] children) { 
    this.ctx = ctx; 
    this.groups = groups; 
    this.children = children; 
} 

public Object getChild(int arg0, int arg1) { 
    // TODO Auto-generated method stub 
    return children[arg0][arg1]; 
} 

public long getChildId(int arg0, int arg1) { 
    // TODO Auto-generated method stub 
    return arg1; 
} 

public View getChildView(int arg0, int arg1, boolean arg2, View arg3, 
     ViewGroup arg4) { 
    if (arg3 == null) { 
     LayoutInflater inflater = LayoutInflater.from(ctx); 
     arg3 = inflater.inflate(R.layout.child, null); 
    } 

    String childData = children[arg0][arg1]; 
    TextView name = (TextView)arg3.findViewById(R.id.child_row_forum_title); 
    TextView desc = (TextView)arg3.findViewById(R.id.child_row_forum_description); 

    if (name != null) 
     name.setText(childData); 

    if (desc != null) 
     // desc.setText(currentSubForum.getDescription()); 

    arg3.setFocusableInTouchMode(true); 
    return arg3;} 

public int getChildrenCount(int arg0) { 
    // TODO Auto-generated method stub 
    return children[arg0].length; 
} 

public Object getGroup(int arg0) { 
    // TODO Auto-generated method stub 
    return groups[arg0]; 
} 

public int getGroupCount() { 
    // TODO Auto-generated method stub 
    return groups.length; 
} 

public long getGroupId(int arg0) { 
    // TODO Auto-generated method stub 
    return arg0; 
} 

public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) { 
    if (arg2 == null) 
    { 
     LayoutInflater inflater = LayoutInflater.from(ctx); 
     arg2 = inflater.inflate(R.layout.group, null); 
    } 


    TextView name = (TextView) arg2.findViewById(R.id.group_item_forum_title); 
    //ImageView image = (ImageView) arg2.findViewById(R.id.group_item_expander_image); 

    if(name != null) 
     name.setText(groups[arg0]);   

    /* 
    if(image != null) { 
     int[][] group_state_sets = {{}, {android.R.attr.state_expanded}}; 
     image.setVisibility(View.VISIBLE); 
     int stateSetIndex = (isExpanded ? 1 : 0) ; 
     Drawable drawable = image.getDrawable(); 
     drawable.setState(group_state_sets[stateSetIndex]); 
    } 
    */ 

    return arg2;} 

public boolean hasStableIds() { 
    // TODO Auto-generated method stub 
    return false; 
} 

public boolean isChildSelectable(int arg0, int arg1) { 
    // TODO Auto-generated method stub 
    return false; 
} 
    } 

     } 
3

सुनिश्चित करें कि आपके कस्टम समूह लेआउट में android:textIsSelectable="false" "सत्य" के रूप में नहीं है, यदि टेक्स्टव्यू में टेक्स्ट चयन करने योग्य पर सेट किया गया है, तो विस्तारणीय सूचीदृश्य जिंजरब्रेड में विस्तारित होगा लेकिन जेलीबीन में नहीं होगा और शायद आईसीएस में भी काम नहीं करेगा।

1

मुझे एक ही समस्या थी और इसे एक्सएमएल पर एक्सपेंडेबल लिस्ट व्यू से android:clickable="true" संपत्ति को हटाकर हल किया गया था।

0

forumListView.collapseGroup (समूहपोजिशन);

forumListView.collapseGroup होना चाहिए (मैं);

10

यदि आपके पास बटन सूची जैसे विजेट पर कोई विजेट है, तो आपको android:focusable="false" इसमें जोड़ना पड़ सकता है। बटन मेरी सूची आइटम को क्लिक करने की इजाजत नहीं दे रहा था। यह मेरे मामले में मुद्दा था।

+0

बहुत बहुत धन्यवाद !! –

+0

इससे मेरी मदद मिली। – Omolara

+0

यदि आप इसे xml में करते हैं तो यह काम नहीं कर सकता है। बटन जोड़ें। सेट फोकसबल (झूठा); जावा में – Immy

1

मैं यह पहले से ही उत्तर दिया गया है, लेकिन जो कुछ भी आप विशेषता के लिए बढ़ा-चढ़ाकर रहे हैं के आधार लेआउट सेट करने का प्रयास:

android:descendantFocusability="blocksDescendants" 
संबंधित मुद्दे