Roll no1
Roll no1

Reputation: 1393

I want to detect ListItem on which onFling event in List View

I have a requirement to change the view of List Item (in ListView) when fling event of right/left swap is identified.

I am able to identify the fling event but question is how i can identify on which item (i want to know position in list)this fling event is happened .

Upvotes: 3

Views: 372

Answers (1)

Michał Z.
Michał Z.

Reputation: 4119

I'm not sure if it's the best way but you can try something like this:

  1. get screen height
  2. count currently visible items (listView.getLastVisiblePosition() - listView.getFirstVisiblePosition())
  3. calculate height of one item (I assume here that all items have the same height): screenheight/numOfItems
  4. if you have Y coordinate of your touch event when fling starts you can calculate which item from the top was clicked: posY/itemHeight
  5. now you can get your item: listView.getItemAtPosition(listView.getFirstVisiblePosition() + valueCalculatedInPreviousPoint)

I didn't tested it so it may not work, it's just an idea.

EDIT: And there is also this lib: https://github.com/47deg/android-swipelistview you can use it or look how they implemented it.

Upvotes: 1

Related Questions