但是当我先单击 Group2 然后单击 Group1 时,它仍返回旧的 Group2 视图...(即convertview应该为空,但其返回旧视图)请告诉我问题出在哪里..我在Stackoverflow上的此处上找到了确切的问题,但还没有解决办法 下面是我的代码 public View getChildView(int groupPosition,int childPosition,boolean isLastChild,View convertView,ViewGroup parent){SingleRow singleRow =新的SingleRow();RequestInfo Req_child =(RequestInfo)getChild(groupPosition,childPosition);字符串类型= Req_child.requestertype;if(convertView == null){开关(类型){案例RequestInfo.REQ_RECEIVED_ACCOUNT:LayoutInflater infalInflater =(LayoutInflater)上下文.getSystemService(Context.LAYOUT_INFLATER_SERVICE);convertView = infalInflater.inflate(R.layout.row_reqlist_acctrcvd,null);convertView.setTag(singleRow);休息;案例RequestInfo.REQ_SENTACCOUNT:LayoutInflater infalInflater1 =(LayoutInflater)上下文.getSystemService(Context.LAYOUT_INFLATER_SERVICE);convertView = infalInflater1.inflate(R.layout.row_reqlist_acctsent,null);convertView.setTag(singleRow);休息;}}singleRow =(SingleRow)convertView.getTag();开关(类型){案例RequestInfo.REQ_RECEIVED_ACCOUNT:singleRow.tvUsername_req_rcd =(TextView)convertView.findViewById(R.id.rw_reqaccts_rcvd_username);singleRow.tvNickName_req_rcd =(TextView)convertView.findViewById(R.id.rw_reqaccts_rcvd_nickname);singleRow.im_gender_req_rcd =(ImageView)convertView.findViewById(R.id.rw_reqaccts_rcvd_profpic);singleRow.btAcceptReq =(按钮)convertView.findViewById(R.id.rw_reqaccts_rcvd_accpt);singleRow.btRjctReq =(按钮)convertView.findViewById(R.id.rw_reqaccts_rcvd_rjct);singleRow.tvUsername_req_rcd.setText(Req_child.requesterUsername);singleRow.tvNickName_req_rcd.setText(Req_child.requesterNickName);singleRow.im_gender_req_rcd.setImageBitmap(Req_child.requestergender.equals("Male")?rmale_pic:rfemale_pic);Log.i("Expand",您的子用户名是" + Req_child.requesterUsername);休息;案例RequestInfo.REQ_SENTACCOUNT:singleRow.tvUsername_req_sent =(TextView)convertView.findViewById(R.id.rw_reqaccts_sent_username);singleRow.tvNickName_req_sent =(TextView)convertView.findViewById(R.id.rw_reqaccts_sent_nickname);singleRow.im_gender_req_sent =(ImageView)convertView.findViewById(R.id.rw_reqaccts_sent_profpic);singleRow.btReqSent =(按钮)convertView.findViewById(R.id.rw_btn_sent_reqaccts);singleRow.tvUsername_req_sent.setText(Req_child.requesterUsername);singleRow.tvNickName_req_sent.setText(Req_child.requesterNickName);singleRow.im_gender_req_sent.setImageBitmap(Req_child.requestergender.equals("Male")?rmale_pic:rfemale_pic);Log.i("Expand",您的子用户名是" + Req_child.requesterUsername);}返回convertView;} 解决方案我只是回答自己的问题,以便对其他人有帮助,我想手动覆盖该方法 getChildTypeCount()和 getChildType(int groupPosition,int childPosition),如果您使用不同的子布局,请在下面找到我的更新代码. @Overridepublic int getChildTypeCount(){返回2;}@Overridepublic int getChildType(int groupPosition,int childPosition){返回groupPosition;}@Override公共视图getChildView(int groupPosition,int childPosition,boolean isLastChild,View convertView,ViewGroup parent){SingleRow singleRow = null;RequestInfo Req_child = childtems.get(groupPosition).get(childPosition);字符串类型= Req_child.requestertype;if(convertView == null){开关(类型){案例RequestInfo.REQ_RECEIVED_ACCOUNT:singleRow =新的SingleRow();convertView = inflater.inflate(R.layout.row_reqlist_acctrcvd,null);singleRow.tvUsername_req_rcd =(TextView)convertView.findViewById(R.id.rw_reqaccts_rcvd_username);singleRow.tvNickName_req_rcd =(TextView)convertView.findViewById(R.id.rw_reqaccts_rcvd_nickname);singleRow.im_gender_req_rcd =(ImageView)convertView.findViewById(R.id.rw_reqaccts_rcvd_profpic);singleRow.btAcceptReq =(按钮)convertView.findViewById(R.id.rw_reqaccts_rcvd_accpt);singleRow.btRjctReq =(按钮)convertView.findViewById(R.id.rw_reqaccts_rcvd_rjct);convertView.setTag(singleRow);休息;案例RequestInfo.REQ_SENTACCOUNT:singleRow =新的SingleRow();convertView = inflater.inflate(R.layout.row_reqlist_acctsent,null);singleRow.tvUsername_req_sent =(TextView)convertView.findViewById(R.id.rw_reqaccts_sent_username);singleRow.tvNickName_req_sent =(TextView)convertView.findViewById(R.id.rw_reqaccts_sent_nickname);singleRow.im_gender_req_sent =(ImageView)convertView.findViewById(R.id.rw_reqaccts_sent_profpic);singleRow.btReqSent =(按钮)convertView.findViewById(R.id.rw_btn_sent_reqaccts);convertView.setTag(singleRow);休息;}}别的{singleRow =(SingleRow)convertView.getTag();}开关(类型){案例RequestInfo.REQ_RECEIVED_ACCOUNT:singleRow.tvUsername_req_rcd.setText(Req_child.requesterUsername);singleRow.tvNickName_req_rcd.setText(Req_child.requesterNickName);singleRow.im_gender_req_rcd.setImageBitmap(Req_child.requestergender.equals("Male")?rmale_pic:rfemale_pic);休息;案例RequestInfo.REQ_SENTACCOUNT:singleRow.tvUsername_req_sent.setText(Req_child.requesterUsername);singleRow.tvNickName_req_sent.setText(Req_child.requesterNickName);singleRow.im_gender_req_sent.setImageBitmap(Req_child.requestergender.equals("Male")?rmale_pic:rfemale_pic);}返回convertView;} I have confusion BaseExpandableListAdapter concept, explained my problem below.Expectation:For example I have two groups , each group holds different layout as child like belowGroup1-ReceivedRequest:child1 - from Layout1child2 - from Layout1Group2-ReceivedSent:child1 - from Layout2child2 - from Layout2Problem:When I click Group1 first and then Group2 its work perfect (i.e. convertview is null when calling for first time on respective group so its inflating right way),But when I click Group2 first and then Group1 its still returning old Group2 view ...(i.e convertview should be null but its returning old view )Kindly route me where is the issue..I found exact ask here on Stackoverflow but there is no solution yetBelow is my code public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { SingleRow singleRow = new SingleRow(); RequestInfo Req_child = (RequestInfo) getChild(groupPosition,childPosition); String type = Req_child.requestertype; if(convertView==null) { switch (type) { case RequestInfo.REQ_RECEIVED_ACCOUNT: LayoutInflater infalInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.row_reqlist_acctrcvd, null); convertView.setTag( singleRow); break; case RequestInfo.REQ_SENTACCOUNT: LayoutInflater infalInflater1 = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater1.inflate(R.layout.row_reqlist_acctsent, null); convertView.setTag(singleRow); break; } } singleRow = (SingleRow) convertView.getTag(); switch (type) { case RequestInfo.REQ_RECEIVED_ACCOUNT: singleRow.tvUsername_req_rcd = (TextView) convertView.findViewById(R.id.rw_reqaccts_rcvd_username); singleRow.tvNickName_req_rcd = (TextView) convertView.findViewById(R.id.rw_reqaccts_rcvd_nickname); singleRow.im_gender_req_rcd = (ImageView) convertView.findViewById(R.id.rw_reqaccts_rcvd_profpic); singleRow.btAcceptReq = (Button) convertView.findViewById(R.id.rw_reqaccts_rcvd_accpt); singleRow.btRjctReq = (Button) convertView.findViewById(R.id.rw_reqaccts_rcvd_rjct); singleRow.tvUsername_req_rcd.setText(Req_child.requesterUsername); singleRow.tvNickName_req_rcd.setText(Req_child.requesterNickName); singleRow.im_gender_req_rcd.setImageBitmap(Req_child.requestergender.equals("Male") ? rmale_pic : rfemale_pic); Log.i("Expand", "your child username is " + Req_child.requesterUsername); break; case RequestInfo.REQ_SENTACCOUNT: singleRow.tvUsername_req_sent = (TextView) convertView.findViewById(R.id.rw_reqaccts_sent_username); singleRow.tvNickName_req_sent = (TextView) convertView.findViewById(R.id.rw_reqaccts_sent_nickname); singleRow.im_gender_req_sent = (ImageView) convertView.findViewById(R.id.rw_reqaccts_sent_profpic); singleRow.btReqSent = (Button) convertView.findViewById(R.id.rw_btn_sent_reqaccts); singleRow.tvUsername_req_sent.setText(Req_child.requesterUsername); singleRow.tvNickName_req_sent.setText(Req_child.requesterNickName); singleRow.im_gender_req_sent.setImageBitmap(Req_child.requestergender.equals("Male") ? rmale_pic : rfemale_pic); Log.i("Expand", "your child username is " + Req_child.requesterUsername); } return convertView; } 解决方案 I just answering my own question so that it will help others, I suppose to override the method manually getChildTypeCount() and getChildType(int groupPosition, int childPosition) incase you have different child layout, Find my below updated code.@Overridepublic int getChildTypeCount() { return 2;}@Overridepublic int getChildType(int groupPosition, int childPosition) { return groupPosition;}@Overridepublic View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { SingleRow singleRow = null; RequestInfo Req_child = childtems.get(groupPosition).get(childPosition); String type = Req_child.requestertype; if(convertView==null ) { switch (type) { case RequestInfo.REQ_RECEIVED_ACCOUNT: singleRow = new SingleRow(); convertView = inflater.inflate(R.layout.row_reqlist_acctrcvd, null); singleRow.tvUsername_req_rcd = (TextView) convertView.findViewById(R.id.rw_reqaccts_rcvd_username); singleRow.tvNickName_req_rcd = (TextView) convertView.findViewById(R.id.rw_reqaccts_rcvd_nickname); singleRow.im_gender_req_rcd = (ImageView) convertView.findViewById(R.id.rw_reqaccts_rcvd_profpic); singleRow.btAcceptReq = (Button) convertView.findViewById(R.id.rw_reqaccts_rcvd_accpt); singleRow.btRjctReq = (Button) convertView.findViewById(R.id.rw_reqaccts_rcvd_rjct); convertView.setTag(singleRow); break; case RequestInfo.REQ_SENTACCOUNT: singleRow = new SingleRow(); convertView = inflater.inflate(R.layout.row_reqlist_acctsent, null); singleRow.tvUsername_req_sent = (TextView) convertView.findViewById(R.id.rw_reqaccts_sent_username); singleRow.tvNickName_req_sent = (TextView) convertView.findViewById(R.id.rw_reqaccts_sent_nickname); singleRow.im_gender_req_sent = (ImageView) convertView.findViewById(R.id.rw_reqaccts_sent_profpic); singleRow.btReqSent = (Button) convertView.findViewById(R.id.rw_btn_sent_reqaccts); convertView.setTag(singleRow); break; } } else { singleRow = (SingleRow) convertView.getTag(); } switch (type) { case RequestInfo.REQ_RECEIVED_ACCOUNT: singleRow.tvUsername_req_rcd.setText(Req_child.requesterUsername); singleRow.tvNickName_req_rcd.setText(Req_child.requesterNickName); singleRow.im_gender_req_rcd.setImageBitmap(Req_child.requestergender.equals("Male") ? rmale_pic : rfemale_pic); break; case RequestInfo.REQ_SENTACCOUNT: singleRow.tvUsername_req_sent.setText(Req_child.requesterUsername); singleRow.tvNickName_req_sent.setText(Req_child.requesterNickName); singleRow.im_gender_req_sent.setImageBitmap(Req_child.requestergender.equals("Male") ? rmale_pic : rfemale_pic); } return convertView;} 这篇关于BaseExpandableListAdapter convertview从getChildView()返回旧视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 23:15