我有listview,其中包含20个按钮,一次只能看到7个元素。所以,滚动列表,使用以下代码...
ListView list_messages = (ListView) solo.getView(android.R.id.list);
.
.
.
View viewAtPosition = getViewByPosition(j, list_messages);
public View getViewByPosition(int position, ListView listView)
{
final int firstListItemPosition = listView.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;
if (position < firstListItemPosition || position > lastListItemPosition) {
return listView.getAdapter().getView(position,
listView.getChildAt(position), listView);
} else {
final int childIndex = position - firstListItemPosition;
return listView.getChildAt(childIndex);
}
}
但问题是,它能够点击前7个按钮,但之后滚动到底部并点击最后一个按钮13次。 任何帮助..?