Hi Mark...
I can see the problem both with the compatibility library (I use a
customized ActionBarSherlock version so that was my initial suspect)
and with native fragments.
You can easily see the behavior with native fragments if you add the
TouchListView library to the APIDemos project and just add a couple of
lines to the FragmentListArray.java class:
public static class ArrayListFragment extends ListFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
Shakespeare.TITLES));
>>> ListView lv = getListView(); // works fine
>>> TouchListView tlv = (TouchListView)getListView(); //
>>> ClassCastException
}
@Override
public void onListItemClick(ListView l, View v, int position,
long id) {
Log.i("FragmentList", "Item clicked: " + id);
}
}
Nick
On Jan 17, 12:10 pm, Mark Murphy <[email protected]> wrote:
> On Tue, Jan 17, 2012 at 12:03 PM, Spiral123 <[email protected]> wrote:
> > as part of updating my app I've decided to drag it into the 21st
> > century and implement Drag and Drop on my ListView Fragment.
>
> I'm not convinced that drag-and-drop is necessarily tied to being part
> of the 21st century. :-)
>
>
>
>
>
>
>
>
>
> > Noodling around for an easy way to do it I came across Mark Murphy's
> > super handy TouchListView library as adapted from TouchInterceptor
> > from the stock Music app. I tried it out and the library works great
> > in a regular app, but for some reason it refuses to work within any
> > ListFragment.
>
> > The line:
>
> > TouchListView tlv=(TouchListView)getListView();
>
> > always causes a ClassCastException: 01-17 11:53:43.705: E/
> > AndroidRuntime(25113): Caused by: java.lang.ClassCastException:
> > android.widget.ListView cannot be cast to
> > com.commonsware.cwac.tlv.TouchListView
>
> > Needless to say TouchListView extends ListView.
>
> > I spent some time working through this and in my testing I've found
> > that:
> > - It's nothing to do with TouchListView - creating my own custom
> > ListView (that doesn't override anything from core) will generate the
> > same error
>
> > - It's not just my app: attaching the TouchListView library to the
> > Google API Demos app and inserting the (TouchListView)getListView() in
> > the FragmentsListArray code generates the same error.
>
> That's strange. Are you using the Android Support package, or native
> fragments? And, can you put together a sample app that demonstrates
> the problem, so I can try it out here?
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> _The Busy Coder's Guide to Android Development_ Version 3.7 Available!
--
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