我继承了一些带有自定义适配器的可扩展列表视图的代码。我试图找出扩展事件的注册位置,以便可以使用另一个组件触发它。我在可扩展列表视图中看不到该组的任何侦听器。从我在日志中使用打印语句可以看出,当我点击分组时,getGroupView() 会被调用。但是,我看不到该方法在哪里被调用或它是如何被调用的。
这是自定义适配器类..
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private String[][] teams;
private String[] league;
private final Context context;
private ImageView imageViewUser;
public MyExpandableListAdapter(String[] groups, String[][] children, Context context) {
this.context = context;
this.teams = children;
this.league = groups;
}
public Object getChild(int groupPosition, int childPosition) {
return teams[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return teams[groupPosition].length;
}
public TextView getGenericView() {
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(context);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
textView.setPadding(56, 0, 0, 0);
return textView;
}
public boolean areAllItemsEnabled() {
return false;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.child_row, null);
}
view.setFocusable(false);
view.setClickable(false);
TextView textView = (TextView) view.findViewById(R.id.grp_child);
textView.setFocusable(false);
textView.setClickable(false);
textView.setText(getChild(groupPosition, childPosition).toString());
//final ImageView imageView;
//imageView = (ImageView) view.findViewById(R.id.imageViewChild);
// imageView.setImageResource(android.R.drawable.ic_menu_gallery);
//imageView.setTag(new ChildPosition(groupPosition,childPosition));
//imageView.setOnClickListener(new OnClickListener(){
/*public void onClick(View arg0) {
// TODO Auto-generated method stub
ChildPosition realPosition = (ChildPosition) imageView.getTag();
Log.d("Shimmer","Click" + "position: " + realPosition.mGroupPosition + " " + realPosition.mChildPosition);
}
});*/
return view;
}
public Object getGroup(int groupPosition) {
System.out.println("Group Clicked!S");
return league[groupPosition];
}
public int getGroupCount() {
return league.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,View view, ViewGroup parent) {
//TextView textView = getGenericView();
System.out.println("I AM HERE!!!!");
if (view == null) {
LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.group_row, null);
}
TextView textView = (TextView) view.findViewById(R.id.row_name);
textView.setText(getGroup(groupPosition).toString());
final ImageView imageView;
imageView = (ImageView) view.findViewById(R.id.imageView1);
imageView.setImageResource(R.drawable.expand);
imageView.setFocusable(false);
imageView.setClickable(true);
imageView.setTag(groupPosition);
imageViewUser = (ImageView) view.findViewById(R.id.usericon);
imageViewUser.setImageResource(R.drawable.user_one);
/* if (view == null) {
LayoutInflater inf = (LayoutInflater) this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.expandlist_group_item, null);
}*/
return view;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}