0

我已通过 Facebook 中的 Json 解析获取评论,并创建扩展列表视图以查看帖子的所有评论,但无法在布局中扩展。请帮我解决这个问题。这是我的 XML 布局

 <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;
}
4

2 回答 2

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;
    }
于 2013-04-09T12:31:37.697 回答
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 ()

于 2013-04-09T12:31:49.540 回答