0

I have listview which contains 20 button and at a time only 7 elements are visible. SO, to scroll the list, iam using the following code...

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);
    }
}

but the problem is , its able to click first 7 buttons but after that it is scrolling to the bottom and clicking last button 13 times.? any help..?

user3297196
  • 47
  • 2
  • 11
  • waht do u mean by "to scroll the list, iam using the following code..."? the list scrolls by itself!, and u can use scrollView at layout, and add the buttons in Vertical LinearLayout – Yazan May 07 '14 at 11:24
  • Use ViewHolder will help you solve your issue. http://stackoverflow.com/questions/24865169/android-listview-using-viewholder – Anees U Feb 11 '15 at 05:40

0 Answers0