使用MergeAdapter;寻找一种方法以确定ListActivity onListItemClicked方法列表项的数据类型 [英] Using MergeAdapter; looking for a way to determine a list item's data type in the ListActivity onListItemClicked method

查看:426
本文介绍了使用MergeAdapter;寻找一种方法以确定ListActivity onListItemClicked方法列表项的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是MergeAdapter创建一个切片列表,列表中的每个部分包含不同类型的基础数据。所有的工作pretty多预期。然而,ListActivity的onListItemClicked方法似乎复杂得多,当涉及到确定潜在选中的列表项的数据类型也是应该的。这样的话,因为我无法找到一个很好的方法来确定,除非我保持列表中的位置的单独的地图对象类型构成了这一选中的项目对象的类型。我希望我可以使用getItemViewType方法返回类似项目同类型的,但是,如果这些项目都在ListView的独立的区域MergeAdapter返回了部分的位置,也就是说,相同的偏移类型值在列表中的一个不同的部分项目的类型都有不同的类型值。我觉得我缺少明显的东西...任何帮助,任何人都可以提供将大大AP preciated。


解决方案

  

我使用的是MergeAdapter创建一个切片列表,列表中的每个部分包含不同类型的基础数据的。


由于 MergeAdapter 项目页的笔记,​​如果你有关于使用这种code的问题,请加入并要求他们在 CW-谷歌Android集团

幸运的是,我看到了你的问题在​​这里。


  

这是这样,因为我无法找到一个很好的方法来确定,除非我保持列表中的位置的单独的地图对象类型构成了这一选中的项目对象的类型。


呼叫的getItem() MergeAdapter 来获得实际的对象,然后用的instanceof 或使用的接口,有事找一个合适的类型对象本身上使用。

I'm using the MergeAdapter to create a sectioned list where each section of the list contains a different type of underlying data. All is working pretty much as expected. However, the ListActivity's onListItemClicked method seems more complicated than it should be when it comes to determining the type of data underlying the selected list item. This is the case because I can't find a good way to determine the type of object that underlies the selected item unless I keep a separate map of list position to object type. I was hoping that I could use the getItemViewType method to return the same type for similar items, but if those items are in separate sections of the ListView, the MergeAdapter returns a type value that offset by the location of the section, i.e., the same type of item in a different section of the list gets a different type value. I feel like I'm missing something obvious... Any help that anyone can provide would be greatly appreciated.

解决方案

I'm using the MergeAdapter to create a sectioned list where each section of the list contains a different type of underlying data.

As the MergeAdapter project page notes, "If you have questions regarding the use of this code, please join and ask them on the cw-android Google Group".

Fortunately for you, I saw your question here.

This is the case because I can't find a good way to determine the type of object that underlies the selected item unless I keep a separate map of list position to object type.

Call getItem() on the MergeAdapter to get the actual object, then use instanceof or use interfaces or something to find an appropriate type to use on the object itself.

这篇关于使用MergeAdapter;寻找一种方法以确定ListActivity onListItemClicked方法列表项的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆