java - how to get index or position of listview control -
hello guys new android programming. want create puzzle game in user sort html unsorted tags dragging them on screen. using listview control store unsorted html tags. have implemented following library: https://github.com/terlici/dragndroplist
now trying position or index of list item after user drop list item can compare user sorted list items actual sorted items.
here code 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 = 0; < 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>
thanks in advance
list.setonitemdragndroplistener(new dragndroplistener(){ public void onitemdrop(dragndroplistview parent, view view, int startposition, int endposition, long id) { super.onitemdrop(parent, view, startposition, endposition, id); log.i("long clicked","pos"+" "+endposition+" id "+id); } });
Comments
Post a Comment