因此,我试图创建一个包含多个父级和子级的可扩展列表。我已经找到了如何找到一组孩子的位置,但是我却无法找到如何将其扩展到其他父母的位置。这是我的代码,
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);
}
TextView txtListChild = (TextView)convertView.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(childPosition==0){
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.reddit.com/r/GlobalOffensive/"));
context.startActivity(i);
}
else if (childPosition ==1){
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://csgolounge.com/"));
context.startActivity(i);
}
else if (childPosition ==2){
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.reddit.com/r/RocketLeague/"));
context.startActivity(i);}
else if (childPosition ==3){
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://rocket-league.com/trading"));
context.startActivity(i);}
}
});
return convertView;
}
每个组中有两个孩子,这仅注册了第一个父组。任何帮助表示赞赏!!!!