Java 带适配器的ExpandableListView

Java 带适配器的ExpandableListView,java,android,Java,Android,我想用自定义适配器创建一个ExpandableListView,但是它只显示我的标题组,当我点击标题(查看子项)时,它什么也不做 (我只希望有一个组项目,因此项目组计数为1) 请帮我找出哪里错了,非常感谢 这是我的适配器: class chatListAdapter extends BaseExpandableListAdapter { private String objectsIdInsideAdapter; private List<String> commentsInside

我想用自定义适配器创建一个ExpandableListView,但是它只显示我的标题组,当我点击标题(查看子项)时,它什么也不做 (我只希望有一个组项目,因此项目组计数为1)

请帮我找出哪里错了,非常感谢

这是我的适配器:

class chatListAdapter extends BaseExpandableListAdapter {
private String objectsIdInsideAdapter;
private List<String> commentsInsideAdapter = new ArrayList<String>();
private List<String> FacebookIdInsideAdapter=new ArrayList<String>();
private List<String> NamesInsideAdapter =new ArrayList<String>();
private Context mContext;

chatListAdapter(String objectId,Context ctx,List<String> comments,List<String> face,List<String> names){
    objectsIdInsideAdapter=objectId;
    mContext=ctx;
    commentsInsideAdapter=comments;
    FacebookIdInsideAdapter=face;
    NamesInsideAdapter=names;
}
@Override
public Object getChild(int arg0, int arg1) {
    // TODO Auto-generated method stub
    return NamesInsideAdapter.get(arg1);
}

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

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View v,
        ViewGroup parent) {
    // TODO Auto-generated method stub

    LayoutInflater inflater = getLayoutInflater();


    if(v==null){
         v = inflater.inflate(R.layout.chat_item, parent, false);
    }



    String comment =commentsInsideAdapter.get(position);
    Button sendCommentBtn =(Button) v.findViewById(R.id.chatitemSendComment);
        TextView commentView= (TextView) v.findViewById(R.id.chateitemViewComment);
        commentView.setText(comment);
        TextView commentName =(TextView) v.findViewById(R.id.chatitemfreindName);
        commentName.setText(NamesInsideAdapter.get(position));
        EditText commentText= (EditText) v.findViewById(R.id.chatitemEnterComment);
        commentText.setVisibility(View.GONE);
        sendCommentBtn.setVisibility(View.GONE);




    return v;
}

@Override
public int getChildrenCount(int arg0) {
    // TODO Auto-generated method stub
    return NamesInsideAdapter.size();
}

@Override
public Object getGroup(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public int getGroupCount() {
    // TODO Auto-generated method stub
    return 1;
}

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

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
        ViewGroup parent) {
    // TODO Auto-generated method stub
    View v = convertView;

    if (v == null) {
        LayoutInflater inflater = getLayoutInflater();
        v = inflater.inflate(R.layout.chat_item_group_layout,parent, false);
    }

    TextView groupName = (TextView) v.findViewById(R.id.groupName);
    TextView groupDescr = (TextView) v.findViewById(R.id.groupDescr);

    groupName.setText("view comments");
    groupDescr.setText("groupDSCR");


    return v;

}

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

@Override
public boolean isChildSelectable(int arg0, int arg1) {
    // TODO Auto-generated method stub
    return false;
}
class chatListAdapter扩展了BaseExpandableListAdapter{
私有字符串ObjectSidInsidedApter;
private List commentsInsideAdapter=new ArrayList();
私有列表FacebookIdInsideAdapter=new ArrayList();
私有列表名称InsidedApter=new ArrayList();
私有上下文;
chatListAdapter(字符串objectId、上下文ctx、列表注释、列表面、列表名称){
ObjectSidInsidedApter=objectId;
mContext=ctx;
commentsInsideAdapter=注释;
FaceBookSideAdapter=面;
NamesInsidedApter=名称;
}
@凌驾
公共对象getChild(int arg0,int arg1){
//TODO自动生成的方法存根
返回NamesInsideAdapter.get(arg1);
}
@凌驾
公共长getChildId(int arg0,int arg1){
//TODO自动生成的方法存根
返回0;
}
@凌驾
公共视图getChildView(int-groupPosition、int-childPosition、boolean-isLastChild、视图v、,
视图组(父级){
//TODO自动生成的方法存根
LayoutInflater充气机=getLayoutInflater();
如果(v==null){
v=充气机。充气(R.layout.chat_项,父项,false);
}
String comment=commentsInsideAdapter.get(位置);
Button sendCommentBtn=(Button)v.findViewById(R.id.chatitemSendComment);
TextView commentView=(TextView)v.findViewById(R.id.chateitemViewComment);
setText(comment);
TextView commentName=(TextView)v.findViewById(R.id.chatitemfreindName);
commentName.setText(namesInsidedApter.get(position));
EditText commentText=(EditText)v.findViewById(R.id.chatitemEnterComment);
commentText.setVisibility(View.GONE);
sendCommentBtn.setVisibility(View.GONE);
返回v;
}
@凌驾
公共整数getChildrenCount(整数arg0){
//TODO自动生成的方法存根
返回namesInsidedApter.size();
}
@凌驾
公共对象getGroup(int arg0){
//TODO自动生成的方法存根
返回null;
}
@凌驾
public int getGroupCount(){
//TODO自动生成的方法存根
返回1;
}
@凌驾
公共长getGroupId(int arg0){
//TODO自动生成的方法存根
返回0;
}
@凌驾
公共视图getGroupView(int-groupPosition、布尔值isExpanded、视图convertView、,
视图组(父级){
//TODO自动生成的方法存根
视图v=转换视图;
如果(v==null){
LayoutInflater充气机=getLayoutInflater();
v=充气机。充气(右侧布局。聊天室项目组布局,父级,false);
}
TextView组名=(TextView)v.findViewById(R.id.groupName);
TextView groupDescr=(TextView)v.findViewById(R.id.groupDescr);
groupName.setText(“查看注释”);
groupDescr.setText(“groupDSCR”);
返回v;
}
@凌驾
公共布尔表ID(){
//TODO自动生成的方法存根
返回false;
}
@凌驾
公共布尔值isChildSelectable(int arg0,int arg1){
//TODO自动生成的方法存根
返回false;
}
这是主要活动中的代码:

ExpandableListView  chat =(ExpandableListView) v.findViewById(R.id.ExpList); 

     String faceids =facebookIdChatInside.get(position);
     String comments = commentInside.get(position);
     String namesChat =nameChatInside.get(position);
     List<String> chatItems = new ArrayList<String>(Arrays.asList(comments.split(",")));
     List<String> facebookids = new ArrayList<String>(Arrays.asList(faceids.split(",")));
     List<String> namesList = new ArrayList<String>(Arrays.asList(namesChat.split(",")));
     chatItems.add(" ");
     facebookids.add(id);
     namesList.add(name);


     chatListAdapter chatA =new chatListAdapter(objectsId.get(position),profileContext,chatItems,facebookids,namesList);
     chat.setAdapter(chatA);
ExpandableListView聊天=(ExpandableListView)v.findViewById(R.id.ExpList);
字符串faceids=facebookIdChatInside.get(位置);
字符串注释=commentInside.get(位置);
字符串namesChat=nameChatInside.get(位置);
List chatItems=new ArrayList(Arrays.asList(comments.split(“,”));
List facebookids=newarraylist(Arrays.asList(faceid.split(“,”));
List namesList=newarraylist(Arrays.asList(namesChat.split(“,”));
添加(“”);
facebookids.add(id);
名称列表。添加(名称);
chatListAdapter chatA=新的chatListAdapter(objectsId.get(位置)、profileContext、chatItems、FaceBookId、NameList);
setAdapter(chatA);

我检查了它,这3个列表不是空的。

阅读您的代码,我发现有3点我不太清楚:

  • getGroup返回null?为什么不返回真实对象
  • getChildId您应该返回一个唯一的标识您孩子的id
  • hasStableIds。返回false。不需要重写此方法
  • 如果你想了解更多关于ExpandableListView的信息,请查看我的博客


    你使用ExpDababelistVIEW就像一个简单的ListVIEW,为什么不考虑一个ListVIEW?< /P> HI,我不想使用ListVIEW,我也看这个指南,GETCHILDID和GETGROUP方法是将保存值作为我的代码返回:尝试替换GeGooRealToAube()宽度LayOutDigabor Posial=(LayOutButter)ctx.getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);您好,仍然只为我显示组标题“查看评论,groupDSCR”,当我单击它时,它不会打开列表…请有人帮助我:)