Привет, ребята, я новичок в программировании на Android. Я хочу создать игру-головоломку, в которой пользователь будет сортировать несохраненные теги html, перетащив их на экран. Я использую элемент управления listview для хранения несортированных тэгов html. Я реализовал следующую библиотеку: https://github.com/terlici/DragNDropListКак получить индекс или позицию элемента управления списком
Теперь я пытаюсь получить позицию или индекс элемента списка после того, как пользователь уронить элемент списка, так что я могу сравнить пользователь отсортированный список элементов в реальных отсортированных элементов.
Вот мой код Main.java
PuzzleManager pm = new PuzzleManager(this);
pm.insertPuzzle("<html>,</h1>,<h1>,</html>,<body>,</body>", "<html>,<body>,<h1>,</h1>,</body>,</html>");
Cursor cursor = pm.getPuzzle(1);
pm.close();
String s = cursor.getString(1);
List<String> puzzleList = Arrays.asList(s.split(","));
ArrayList<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
for(int i = 0; i < puzzleList.size(); ++i) {
HashMap<String, Object> item = new HashMap<String, Object>();
item.put("puzzle", puzzleList.get(i));
items.add(item);
}
DragNDropListView list = (DragNDropListView)findViewById(android.R.id.list);
DragNDropSimpleAdapter adaptor = new DragNDropSimpleAdapter(this,
items,
R.layout.row,
new String[]{"puzzle"},
new int[]{R.id.text},
R.id.handler);
list.setDragNDropAdapter(adaptor);
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.terlici.dragndroplist.DragNDropListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80px"
android:orientation="horizontal"
android:gravity="center_vertical"
>
<ImageView
android:id="@+id/handler"
android:layout_width="60px"
android:layout_height="60px"
android:src="@android:drawable/btn_star_big_on"
android:layout_marginLeft="8px"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Заранее спасибо
«DragNDropListView предоставляет прослушиватель событий для перетаскивания»: * list.setOnItemDragNDropListener (...) *. Используйте его, чтобы получить индекс отбрасываемого предмета (** id **) – Rami