Java 如何在ExpandableListView的组中设置文本文本视图
我想做的是,当我在ExpandableListView中单击子级时,它将根据所选子级更改父级(groupView)。简而言之,这就像HTML中的Java 如何在ExpandableListView的组中设置文本文本视图,java,android,expandablelistview,expandablelistadapter,Java,Android,Expandablelistview,Expandablelistadapter,我想做的是,当我在ExpandableListView中单击子级时,它将根据所选子级更改父级(groupView)。简而言之,这就像HTML中的 这是儿童视图 public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { final Strin
这是儿童视图
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflater= (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("Onclick CHild: ", childText);
//This is where I want to setText the View of its groupView
}
});
TextView txtListChild = (TextView) convertView
.findViewById(R.id.listItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch(groupPosition){
case 0:{
convertView = infalInflater.inflate(R.layout.type_header, null);
break;
}
case 1:{
convertView = infalInflater.inflate(R.layout.make_header, null);
break;
}
case 2:{
convertView = infalInflater.inflate(R.layout.model_header, null);
break;
}
case 3:{
convertView = infalInflater.inflate(R.layout.engine_header, null);
break;
}
case 4:{
convertView = infalInflater.inflate(R.layout.weight_header, null);
break;
}
}
}
Holder holder = new Holder(this._context);
holder.title = (TextView) convertView.findViewById(R.id.headerTitle);
holder.title.setText(headerTitle);
return convertView;
}
这是组视图
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflater= (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("Onclick CHild: ", childText);
//This is where I want to setText the View of its groupView
}
});
TextView txtListChild = (TextView) convertView
.findViewById(R.id.listItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch(groupPosition){
case 0:{
convertView = infalInflater.inflate(R.layout.type_header, null);
break;
}
case 1:{
convertView = infalInflater.inflate(R.layout.make_header, null);
break;
}
case 2:{
convertView = infalInflater.inflate(R.layout.model_header, null);
break;
}
case 3:{
convertView = infalInflater.inflate(R.layout.engine_header, null);
break;
}
case 4:{
convertView = infalInflater.inflate(R.layout.weight_header, null);
break;
}
}
}
Holder holder = new Holder(this._context);
holder.title = (TextView) convertView.findViewById(R.id.headerTitle);
holder.title.setText(headerTitle);
return convertView;
}
公共视图getGroupView(int groupPosition、布尔isExpanded、视图convertView、视图组父级){
字符串头文件=(字符串)getGroup(groupPosition)
请使用此代码