我正在使用一些列表项布局,在项目布局中,有一个 Viewstub 我想在其中放置一些图像。我没有列表项布局的来源,只知道其中有一些 TextViews 和 ViewStubs。
我的目的是先找到 ViewStub 并设置我的个人布局并使用它。但是,无法找到某些 ViewStub。
public class TJAdapter extends CursorAdapter {
....
public void bindView(View view, Context context, Cursor cursor) {
View item = view;
ViewStub contentstub = (ViewStub)item.findViewById(R.id.content_stub);
if (contentstub == null){
LOG.error("TJ,contentstub is null");
} else {
LOG.error("TJ,contentstub is not null");
contentstub.setLayoutResource(R.layout.icon_image);
View iconImage = contentstub.inflate();
}
....
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(R.layout.list_item, parent, false);
bindView(view, context, cursor);
}
}
并且日志输出是这样的:
TJ,bindView is called
TJ,contentstub is not null
TJ,bindView is called
TJ,contentstub is null
TJ,bindView is called
TJ,contentstub is not null
TJ,bindView is called
TJ,contentstub is not null
TJ,bindView is called
TJ,contentstub is null
TJ,bindView is called
TJ,contentstub is not null
我花了很多时间在上面,不知道为什么会这样。
一些身体可以帮助吗?
==================================================== ================
正如 blahdiblah 建议的那样,现在我可以找到 iconImage。但是我不太明白为什么下一项会受到影响,我不能再按列表项了。它没有回应。
ImageButton iconImage = null;
ViewStub contentstub = (ViewStub)item.findViewById(R.id.content_stub);
if (contentstub == null){
LOG.error("TJ,contentstub is null");
iconImage = (ImageButton)item.findViewById(R.id.icon_image);
} else {
LOG.error("TJ,contentstub is not null");
contentstub.setLayoutResource(R.layout.list_item_icon_image);
View image = contentstub.inflate();
iconImage = (ImageButton)image.findViewById(R.id.icon_image);
}
if (iconImage == null) {
LOG.error("TJ,iconImage is null");
} else {
LOG.error("TJ, iconImage is not null");
}