On Sat, May 30, 2009 at 12: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?


Why do you say that your app and the Music app are doing things "exactly the
same way", when you're not using a TouchInterceptor as your listview? If
your listview is not derived from TouchInterceptor, then obviously you
cannot just pretend that it is and call TouchInterceptor methods on a plain
ListView.
So as a first step, you should make your app use a TouchInterceptor instead
of a plain ListView.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to