我通过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;
}
答案 0 :(得分: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;
}
答案 1 :(得分: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 ()