此活动中的 findViewWithTag 返回 null,但 CustomExpandableListAdapter 中的 Log 输出正确。我在这里做错了什么?
public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
//normal stuff
public View getGroupView(int groupPosition, boolean isLastChild,
View view, ViewGroup parent) {
CustomObject group = (CustomObject) getGroup(groupPosition);
//normal stuff
LinearLayout toggle = (LinearLayout) view.findViewById(R.id.toggle);
//group.getId() returns an int
toggle.setTag("toggle" + group.getId());
Log.i("BBBBBtoggleadapterBBBBBB", toggle.getTag().toString());
return view;
}
}
public class MainActivity extends BaseListActivity {
//normal stuff
//this is an xml onClick
public void toggleView(View view) {
String groupId = view.getTag().toString();
//LinearLayout toggle = (LinearLayout) view.findViewWithTag("toggle " + groupId);
Log.i("BBBBBBBBBtoggleactivityBBBBBBBBBB", "toggle" + groupId);
/*if (toggle == null) {
Toast.makeText(getBaseContext(), "null", Toast.LENGTH_LONG).show();
}*/
}
}
编辑:更新代码,在活动和适配器中记录“切换”+ id,它们是相同的