-1

I'm programming an quiz app. I have a TextView with a Question. The Textview height is changing depending on the question. Under the textview is a listview with the answers. I want to do something if the listview contains more items than i can see. So if there is a new question i write the text into the textview and fill the quesitons as item in the listview. After that I make listView.getLastVisiblePosition(); but it is always -1. When i make a extra button and and put the mehtode inside it returns the correct lastVisiblePosition. So I tried to get the height of all items in the listview (and the dividers) and compare this height with the listview.getHeight. But the Listview height is always bigger then the itemsheight. So I tried listview.canScrollVertically but it is always true.

So I have no idea how i can check if i can see all items in de listview or i have to scroll.

Nico H
  • 3
  • 1
  • 3
  • Just compare `(listView.getLastVisiblePosition() - listView.getFirstVisiblePosition())` with total list items – Rami Apr 12 '15 at 19:11
  • Thanks but the lastVisiblePosition is -1. I dont want to have an extra button to check it. If a user answered a question, he has to click at a button which checks if the answer is right. If the answer is write I replace the text of the textview with the new question, load the new answers in the textview and want to check if every item is shown or he has to scroll and at this time it is -1. If i dont check it an make an extra button to check it, it gives the right position but I dont want a extra button. – Nico H Apr 12 '15 at 19:21

1 Answers1

0

Ok, I've got an answer. It is maybe not the best but it is working.

Just make a short break.

 new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            // Compare it here
        }
    }, 10);
Nico H
  • 3
  • 1
  • 3