-1

I have a listview where pople can click on items. When they do, they increase height and show more information.

However, when clicking the bottom item, it is not visible to the user that the item height has increased and there is content if you scroll down.

Using e.g. following code in onItemClick does not solve the problem:

    if (position == myItemsDataArrayList.size() - 1) {
      if (data.ui_flags == "clicked") {
        catalogListView.smoothScrollToPosition(position);
      }
    }
Tom
  • 3,587
  • 9
  • 69
  • 124
  • 1
    http://stackoverflow.com/questions/3606530/listview-scroll-to-the-end-of-the-list-after-updating-the-list – Ivan Skoric Aug 06 '13 at 18:54
  • @androbat I will try out the solutions mentioned there. (However, I think one problem is that the item is already selected... Hence e.g. seting it selected won't help Android detect bottom item size increased and it needs to rescroll. That said, worth trying! Thanks!) – Tom Aug 06 '13 at 18:56
  • Try it and we'll see. Hope it helps, tell me how it went. – Ivan Skoric Aug 06 '13 at 19:00
  • It worked (!) - make it an aswer, and I will accept it :) – Tom Aug 06 '13 at 21:58

2 Answers2

1

Implement this function in your if statement.

private void scrollMyListViewToBottom() {
myListView.post(new Runnable() {
    @Override
    public void run() {
        // Select the last row so it will scroll into view...
        myListView.setSelection(myListAdapter.getCount() - 1);
    }
});
}

code by: https://stackoverflow.com/a/7032341/2197087

Community
  • 1
  • 1
Ivan Skoric
  • 1,200
  • 8
  • 18
0

Working code solution was this:

catalogListView.post(new Runnable() {
  @Override
  public void run() { 
    catalogListView.setSelection(position_final);
  }
});
Tom
  • 3,587
  • 9
  • 69
  • 124