在我的getView方法中,我想获取特定的子视图。我知道我的适配器包含多个项目,通过调用getCount:
getCount();
根据JavaDoc:
public abstract int getCount ()
Added in API level 1
How many items are in the data set represented by this Adapter.
现在在我的getView方法中:
public View getView(final int position, View convertView, ViewGroup parent) {
View lastAddedItem = parent.getChildAt(getCount()-1);
if(lastAddedItem == null) {
Log.w("ListAdapter", "View is null");
}
}
这个消息总是出现在 LogCat
中,意味着我试图获取的视图是 null
。
我也尝试过这样做:
View lastAddedItem = parent.getChildAt(parent.getChildCount()-1);
那么如何从我的
ViewGroup
对象中获取特定的视图?