Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging list order after dragging in android
    primarykey
    data
    text
    <p>I am using Drag n Drop in my list view.Its working very fine but the problem is how i change the order of elements after dragging too.Suppose i have a list view with elements 1 at 0 position, 2 at 1 position 3 at 2 position and so on. So when i click on the item at position 2 it is giving me item at position 1 and it is right too but after dragging suppose i replace 2 by 1.it should give me data that is associated with 1 but it is again giving me data of 2.so how it is possible.any help would be appreciated.</p> <p>here is my code:</p> <pre><code>public class DragNDropListActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dragndroplistview); Button mbtn=(Button)findViewById(R.id.button12); mbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i=new Intent(DragNDropListActivity.this,FormulaActivity.class); startActivity(i); finish(); } }); ArrayList&lt;String&gt; content = new ArrayList&lt;String&gt;(mListContent.length); for (int i=0; i &lt; mListContent.length; i++) { content.add(mListContent[i]); } setListAdapter(new DragNDropAdapter(this, new int[]{R.layout.dragitem}, new int[] {R.id.TextView01}, content));//new DragNDropAdapter(this,content) ListView listView = getListView(); if (listView instanceof DragNDropListView) { ((DragNDropListView) listView).setDropListener(mDropListener); ((DragNDropListView) listView).setRemoveListener(mRemoveListener); ((DragNDropListView) listView).setDragListener(mDragListener); } } private DropListener mDropListener = new DropListener() { public void onDrop(int from, int to) { ListAdapter adapter = getListAdapter(); if (adapter instanceof DragNDropAdapter) { ((DragNDropAdapter)adapter).onDrop(from, to); getListView().invalidateViews(); } } }; private RemoveListener mRemoveListener = new RemoveListener() { public void onRemove(int which) { ListAdapter adapter = getListAdapter(); if (adapter instanceof DragNDropAdapter) { ((DragNDropAdapter)adapter).onRemove(which); getListView().invalidateViews(); } } }; private DragListener mDragListener = new DragListener() { int backgroundColor = 0xe0103000; public void onDrag(int x, int y, ListView listView) { // TODO Auto-generated method stub } public void onStartDrag(View itemView) { itemView.setVisibility(View.INVISIBLE); itemView.setBackgroundColor(backgroundColor); ImageView iv = (ImageView)itemView.findViewById(R.id.ImageView01); if (iv != null) iv.setVisibility(View.VISIBLE); } public void onStopDrag(View itemView) { itemView.setVisibility(View.VISIBLE); itemView.setBackgroundColor(backgroundColor); ImageView iv = (ImageView)itemView.findViewById(R.id.ImageView01); if (iv != null) iv.setVisibility(View.VISIBLE); } }; private static String[] mListContent={"1","2","3"}; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload