kiran
kiran

Reputation: 3264

How to know which list item is visible to user?

I recorded videos through my app,And i stored in memory card.

After i get those videos and added to list view .

Based on screen size only one video is visible to user.

If user scroll up and down and stop.

At that point i want to know which one is in front of user.

If any one know the solution please help me.or any other way to do

Thanks in advance

Upvotes: 3

Views: 4848

Answers (4)

Jaiprakash Soni
Jaiprakash Soni

Reputation: 4112

As you are showing only one item of list so you can create a function in your Adapter class that will gives you id of currently visible child. like

public class MyAdapter extends BaseAdapter{ int slectedChild; // selectedChild will save currently visible child's id

public int getSelectedChild(){ // this function will return id of currently visible child
return selectedChild;
}

// public View getView(int position, View convertView, ViewGroup container)
{

selectedChild=position; // update value selectedChild in side getView() function.
....
}
}

Upvotes: 0

Tom
Tom

Reputation: 1793

Given Marek Sebera's comment - it is indeed true that getView won't be 100% reliable, you can just use getFirstVisiblePosition in the adapter.

(That should be enough if only one video is visible at a time.)

Upvotes: 0

faylon
faylon

Reputation: 7450

OK, there are two methods could help you.

ListView.getFirstVisiblePosition()
ListView.getLastVisiblePosition()

Look this page for details.

Upvotes: 11

Sean
Sean

Reputation: 5256

If you are using an Adapter to populate your list, the last visible item will be the one that pops into your latest getView.

Meaning, if you'll keep track of what was the latest Position - you'll store the position of the last visible item.

Upvotes: 0

Related Questions