Android ExpandableListView的组视图充气错误
我正在我的项目中实现ExpandableListView,我有以下问题 在我提供给扩展BaseExpandableListAdapter的expandablelistview适配器的列表中,有一个名为Type的变量。仅基于类型1、2或3的值,我正在膨胀3种不同布局中的一种。因此,我的getGroupViewAndroid ExpandableListView的组视图充气错误,android,android-layout,expandablelistview,Android,Android Layout,Expandablelistview,我正在我的项目中实现ExpandableListView,我有以下问题 在我提供给扩展BaseExpandableListAdapter的expandablelistview适配器的列表中,有一个名为Type的变量。仅基于类型1、2或3的值,我正在膨胀3种不同布局中的一种。因此,我的getGroupView @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertV
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService
(Activity.LAYOUT_INFLATER_SERVICE);
final int type = ((cast) getGroup(groupPosition)).getType();
if(convertView == null){
if(type == 1){
convertView = inflater.inflate(R.layout.layout1, parent, false);
}else if(type == 2){
convertView = inflater.inflate(R.layout.layout2, parent, false);
}else if(type == 3){
convertView = inflater.inflate(R.layout.layout3, parent, false);
}
}
TextView text = (TextView) convertView.findViewById(R.id.tvID);
text.setText("some text");
return convertView;
}
因此,当活动最初加载时,一切正常。但是当我扩展第一个组时,下面的组的布局也会改变。展开第二组,并将组3、4、5……的布局改为1……等。当我崩溃时,一切都很好
这里有什么问题吗?我遗漏了什么吗?我的方法正确吗
此外,由于我正在膨胀3种不同的布局,我如何获得对不同元素的引用SimageView、textview,。。。在那些布局中,以便我可以用所需的值填充它们
编辑:完整适配器实现
public class EventExpandableListViewAdapter extends BaseExpandableListAdapter{
/* Class1 {
var1;
var2;
...
ArrayList<Class2> var3;
}
*/
Context context;
final List<Class1> events;
public EventExpandableListViewAdapter(Context context, ArrayList<Class1> events) {
this.context = context;
this.events = events;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return events.get(groupPosition).getVar3().get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if(convertView == null){
convertView = inflater.inflate(R.layout.childlayout, parent, false);
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return events.get(groupPosition).getVar3().size();
}
@Override
public Object getGroup(int groupPosition) {
return events.get(groupPosition);
}
@Override
public int getGroupCount() {
return events.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService
(Activity.LAYOUT_INFLATER_SERVICE);
final int type = ((cast) getGroup(groupPosition)).getType();
if(convertView == null){
if(type == 1){
convertView = inflater.inflate(R.layout.layout1, parent, false);
}else if(type == 2){
convertView = inflater.inflate(R.layout.layout2, parent, false);
}else if(type == 3){
convertView = inflater.inflate(R.layout.layout3, parent, false);
}
}
TextView text = (TextView) convertView.findViewById(R.id.tvID);
text.setText("some text");
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
编辑2:我试图创建3个不同布局的幻觉,只使用1个布局,并根据类型的值隐藏/显示不同的视图。仍然是相同的结果。从0开始检查以下类型的条件:
if(type == 0){
convertView = inflater.inflate(R.layout.layout1, parent, false);
}else if(type == 1){
convertView = inflater.inflate(R.layout.layout2, parent, false);
}else if(type == 2){
convertView = inflater.inflate(R.layout.layout3, parent, false);
}
用完整的文本更新您的问题adapter@EngrWaseemArain类型的值是我为测试目的硬编码的东西。。我知道确切的价值。。您的解决方案有何帮助?