Also note the special list item layout you need (see edit_track_list_item in the music app).
On Mon, Jun 1, 2009 at 5:53 PM, Ben Roberts <[email protected]> wrote: > > Never mind I figured it out. I had to override the builtin layout with > my own layout which assigned a TouchInterceptor as the ListView for > the ListActivity. > > On May 30, 3:48 pm, Ben Roberts <[email protected]> wrote: > > I'm trying to write an app which will present a list of items to the > > user that can be reordered, so I want to use the same code that's used > > in the Music app to reorder items in a playlist. This is controlled > > via com.android.music.TouchInterceptor, which extends ListView. > > > > I copied this file into my project, changed the package to my own, > > changed all references to mContext (a private field in ListAdaptor) to > > getContext() because I was getting compile errors, and changed the R.* > > references to my own layout ID's and icons. There are no other changes > > to the class. > > > > In the Music app, TrackBrowserActivity sets up move listeners on its > > ListView using this: > > > > public class TrackBrowserActivity extends ListActivity > > implements View.OnCreateContextMenuListener, MusicUtils.Defs, > > ServiceConnection > > { > > [...] > > private ListView mTrackList; > > [...] > > /** Called when the activity is first created. */ > > @Override > > public void onCreate(Bundle icicle) > > { > > [...] > > mTrackList = getListView(); > > mTrackList.setOnCreateContextMenuListener(this); > > if (mEditMode) { > > //((TouchInterceptor) mTrackList).setDragListener > > (mDragListener); > > ((TouchInterceptor) mTrackList).setDropListener > > (mDropListener); > > ((TouchInterceptor) mTrackList).setRemoveListener > > (mRemoveListener); > > mTrackList.setCacheColorHint(0); > > } else { > > > > ...so I tried doing the same thing in my app: > > > > public class MyClass extends ListActivity implements > > OnCreateContextMenuListener { > > [...] > > private ListView mItemList; > > [...] > > @Override > > protected void onCreate(Bundle icicle) { > > [...] > > mItemList=getListView(); > > mItemList.setOnCreateContextMenuListener(this); > > ((TouchInterceptor)mItemList).setDropListener(mDropListener); > > ((TouchInterceptor)mItemList).setRemoveListener > > (mRemoveListener); > > > > ...but my code results in a ClassCastException. That actually doesn't > > surprise me since the ListView in my ListActivity is not an instance > > of TouchInterceptor, but how come it works in the Music app when it's > > doing things exactly the same way? I tried this on the 1.1 SDK and > > just upgraded to 1.5 to check it there, and it occurs under both. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

