3

当识别出左右交换的投掷事件时,我需要更改列表项的视图(在 ListView 中)。

我能够识别出投掷事件,但问题是 我如何确定该投掷事件发生在哪个项目(我想知道列表中的位置)上。

4

1 回答 1

1

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.

于 2013-04-16T08:30:36.847 回答