カスタム アダプターを使用して ExpandableListView を作成したいのですが、タイトル グループしか表示されず、タイトルをクリックしても (子アイテムを表示するために) 何もしません (グループ アイテムを 1 つだけにしたいので、アイテム グループ カウントは 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;
}
これはメイン アクティビティのコードです。
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);
確認しましたが、これらの 3 つのリストは空ではありません。