3

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

kiran
  • 3,244
  • 7
  • 34
  • 57
  • Read http://stackoverflow.com/questions/6740089/android-getting-a-count-of-the-visible-children-in-a-listview – Pankaj Kumar Jul 19 '13 at 09:55
  • Also check the provided link: http://stackoverflow.com/questions/15874260/determine-if-a-view-is-on-screen-android – karma Jul 28 '15 at 20:35

4 Answers4

11

OK, there are two methods could help you.

ListView.getFirstVisiblePosition()
ListView.getLastVisiblePosition()

Look this page for details.

faylon
  • 7,360
  • 1
  • 30
  • 28
  • `ListView` extends `AdapterView`. Hence, JavaDoc for `ListView` will not help a lot, use [JavaDoc](https://developer.android.com/reference/android/widget/AdapterView.html#getFirstVisiblePosition()) für `AdapterView` instead. – Timo Bähr Jun 29 '17 at 09:36
0

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.

Sean
  • 5,176
  • 2
  • 34
  • 50
  • First part of answer is not right ultimately. Android can pre-cache, and if scrolling up and down you need to find out how many items user can see. – Marek Sebera Jul 19 '13 at 09:55
  • @MarekSebera you are right, but the guy said `Based on screen size only one video is visible to user.` – Sean Jul 19 '13 at 09:56
0

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.)

Tom
  • 1,773
  • 15
  • 23
0

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.
....
}
}

Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67