If the ListView
only shows 5 items, and the all data is 40 items. How can I get the current selection is which position in visible items (1~5)? I have tried getSelectedItemPosition
but it will return the position in all data. I want the position number in visible items shows on each item.
class MyAdapter extends BaseAdapter {
@Override
public int getCount(){
...
}
@Override
public Object getItem(int position){
...
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
// I want to get the position number in visible items here
}
}
getFirstVisiblePosition()
can get first visible position in all items,so you can use getSelectedItemPosition()-getFirstVisiblePosition()
to make it.
getFirstVisiblePosition()
can get first visible position and getLastVisiblePosition()
can get last visible position.
So getLastVisiblePosition()-getFirstVisiblePosition()
returns the number of visible item.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With