android - Drag and drop in a list view -


i have little experience android.

i'm trying make drag+drop aware list view because various other solutions don't client wants, , project going have me making lot of other "fun" draggy-droppy-swipey things while.

the requirements simple: user can drag thing list out , else using android drag+drop api (if call that). works long said things aren't in list view or intercepts long presses or whatever.

here's isn't working far:

package blah;  import android.os.*; import android.app.*; import android.content.*; import android.util.*; import android.view.*; import android.view.view*; import android.widget.*;  public class listfragment extends fragment {     public static class itemview extends textview     {         public int position;          public itemview(context context, attributeset attrs)         {             super(context,attrs);         }     }      private class _adapter extends baseadapter     {         private activity _activity;          @override         public int getcount()         {             // test: make go             return 16;         }          @override         public object getitem(int arg0)         {             return null;         }          @override         public long getitemid(int arg0)         {             return 0;         }          @override         public view getview(int position, view convert, viewgroup parent)         {             layoutinflater inflater = (layoutinflater)this._activity.getsystemservice(                     context.layout_inflater_service                     );              itemview itemview = (itemview)inflater.inflate(r.layout.list_item_view,parent,false);               // test: display positions             itemview.settext(integer.tostring(position));              itemview.setonclicklistener(new _itemclicklistener());              itemview.setondraglistener(new _itemdraglistener());              itemview.position = position;              return itemview;         };          public _adapter(activity activity)         {             this._activity = activity;         }     }      private class _itemdraglistener implements ondraglistener     {         @override         public boolean ondrag(view view, dragevent event)         {             itemview targetitemview = (itemview)view;              int action = event.getaction();              switch(action){             case dragevent.action_drop:                 {                     // not sure which here, since nothing works                     itemview sourceitemview = (itemview)event.getlocalstate();                      log.d("derp",                             "dropped " + integer.tostring(sourceitemview.position) +                             " onto " + integer.tostring(targetitemview.position)                             );                 }break;             }             return true;         }     }      private class _itemclicklistener implements onclicklistener     {         @override         public void onclick(view view)         {             itemview itemview = (itemview)view;             log.d("derp", integer.tostring(itemview.position) + " clicked");              // nothing happens here             view.startdrag(                 clipdata.newplaintext("",""),                 new view.dragshadowbuilder(view),                 view,                 0                 );         }          public _itemclicklistener()         {         }     }      private activity _activity;      @override     public void onattach(activity activity)     {         super.onattach(activity);         this._activity = activity;     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate)     {         listview listview = (listview)inflater.inflate(r.layout.list_fragment, container, false);          listview.setadapter(new _adapter(this._activity));          return listview;     } } 

my intuition tells me making drag+drop list should simpler this, given "breadth" of features supported android ui. however, java, i'm not expecting straightforward answers.

here link of drag , drop list view demo

in android 4.0, drag , drop of views supported. here full demo exlpanation of drag , drop listview


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -