In listview,Viewstub cannot be found after the previous one is inflate
Posted
by
user2958132
on Stack Overflow
See other posts from Stack Overflow
or by user2958132
Published on 2013-11-05T21:52:28Z
Indexed on
2013/11/05
21:53 UTC
Read the original article
Hit count: 441
I am using some list item layout and in the item layout, there is a Viewstub where I want to put some image in.I don't have the source of list item layout and just know there are some TextViews and ViewStubs in it.
My purpose is to find the ViewStub first and set my personal layout and play with it. However, some of the ViewStub cannot be found.
public class TJAdapter extends CursorAdapter {
....
public void bindView(View view, Context context, Cursor cursor) {
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);
}
And the log output is like this:
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
I spent a lot of time on it and have no idea why this happens.
Can some body help?
© Stack Overflow or respective owner