我需要更改ListView行内ImageView中使用的可绘制资源。 我正在使用这个:
int wantedPosition = 10; // Whatever position you're looking for
int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); // This is the same as child #0
int wantedChild = wantedPosition - firstPosition;
// Say, first visible position is 8, you want position 10, wantedChild will now be 2
// So that means your view is child #2 in the ViewGroup:
if (wantedChild < 0 || wantedChild >= listView.getChildCount()) {
Log.w(TAG, "Unable to get view for desired position, because it's not being displayed on screen.");
return;
}
View wantedView = listView.getChildAt(wantedChild);
如果我在findViewById
内搜索wantedView
,我找不到我正在寻找的ImageView
。
如何引用此ImageView来设置另一个可绘制资源?
答案 0 :(得分:0)
快捷方式:使用setTag(position)
(或getItem
或任何您想要设置的标记作为适配器View
方法或相对内容的getView
和进一步使用listView.findViewByTag