2013-04-09 18 views
0

我有通過Facebook中的Json解析獲取評論,我創建了擴展列表視圖以查看帖子的所有評論,但它無法在佈局中擴展。請幫我解決這個問題。 這是我的XML佈局ExpandedList視圖在Android中不能正常工作

<ExpandableListView 
    android:id="@+id/expandableListView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:groupIndicator="@null"> 
</ExpandableListView> 

而且我的代碼

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 

    int s=ConstantsValues.commentsResponse.get(position).size(); 

    View view=convertView; 
    LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    view=inflater.inflate(R.layout.custom_expandablecomments_parentgroup, parent,false); 
    TextView tv1=(TextView)view.findViewById(R.id.textView_GROUP); 
    tv1.setText("Click hee to see " +s+" comments"); 
    tv1.setPadding(100, 0, 0,0); 
    return view; 
} 
public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) { 

    HashMap<String, Object> hashmap= ConstantsValues.commentsResponse.get(groupPosition).get(childPosition); 
    View view=convertView; 
    position=childPosition; 
    LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    view=inflater.inflate(R.layout.custom_expandable_comments, parent,false); 
    ImageView imv=(ImageView)view.findViewById(R.id.Imageview_profipic_commentsShow); 
    TextView tv1=(TextView)view.findViewById(R.id.textView_Name_CommentShow); 
    TextView tv2=(TextView)view.findViewById(R.id.textView_Comments_show); 
    imv.setImageBitmap((Bitmap)hashmap.get("Image")); 
    tv1.setText((String)hashmap.get("UserName")); 
    tv2.setText((String)hashmap.get("CommentsFull")); 

    return view; 
} 
+0

發生了什麼事..What的問題 – Pragnani 2013-04-09 12:09:34

+0

@Pragnani整個評論即時取不其展開。 – 2013-04-09 12:24:28

+0

檢查是否有任何異常或在logcat ..如果發佈的錯誤.. – Pragnani 2013-04-09 12:26:04

回答

0

使用此代碼....希望它可以幫助你......

@Override 
    public void onGroupExpanded(int groupPosition){ 
     //collapse the old expanded group, if not the same 
     //as new group to expand 
     if(groupPosition != lastExpandedGroupPosition){ 
      accordion.collapseGroup(lastExpandedGroupPosition); 
     } 

     super.onGroupExpanded(groupPosition);   
     lastExpandedGroupPosition = groupPosition; 
    } 
+0

HI爲我的功能工作正常,得到飼料,但用戶界面只得不到它。在我的XML佈局中,我已經爲FB的牆貼提供了一個List視圖。在那個佈局本身,我在下面有Expandable列表視圖。如果我按父母文本,它不擴展到顯示已經有評論。 – 2013-04-09 12:45:18

+0

@ManojKumar花一些時間閱讀這兩個鏈接,確保你會得到它... http://androidtrainningcenter.blogspot.in/2012/07/android-expandable-listview-simple.html和http:// developer。感謝Nandu的android.com/reference/android/widget/ExpandableListView.html – Nandu 2013-04-09 13:00:40

+0

。讓我們來看看 – 2013-04-09 13:14:55

0

如果你想要默認擴展組,然後執行此操作:

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    View v = super.getGroupView(groupPosition, isExpanded, convertView, parent); 
    ExpandableListView eLV = (ExpandableListView) parent; 
    eLV.expandGroup(groupPosition); 
    return v; 
} 

即使用expandGroup()