Android的 - 的ListView适配器,带的两个视图项目 [英] Android - ListView Adapter with items of two views

查看:183
本文介绍了Android的 - 的ListView适配器,带的两个视图项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的新的编程和我被困在了两天,我似乎无法来解决的情况。结果
我已经得到了应使用具有几乎没有simularity两种不同的观点来填充一个ListActivity。直到如今我用MergeAdapter它工作得很好,但我的结果是这样的:
适配器1,适配器2。我没有要改变来列表中的项目的顺序的能力。
我的问题是:是否有可能创建一个持有两种观点的项目,而不是两个观点适配器,所以我有我的项目的方式我输入他们整理的适配器?
为了简便起见,我得到了这两个项目的ArrayList,每个人都有INT位置,所以我就可以将它们插入到按位置排序的名单。结果
编辑:我​​试过延伸BaseAdapter但再次,我需要两个适配器,因为我已经在网上阅读,但如果我这样做,我将无法控制项目的地方就行了。
我希望我更清楚这一次。
欢迎任何回应。结果
谢谢你。

I'm new at Android programming and I'm stuck in a situation for two days that I can't seem to solve.
I've got a ListActivity that should be populated with two different views that has almost no simularity. Untill now I've used MergeAdapter and it worked fine but my outcome was like this: Adapter1,Adapter2. and I didn't have the ability to change the order of the items coming to the list. My question is: is it possible to create an adapter that is holding items of two views and not adapters of two views so I'll have my items sorted by the way I input them? For simplicity sake, I got an ArrayList of those two items and each has "int position" so I'll be able to insert them into the list sorted by position.
I've tried extending BaseAdapter but once again I need two adapters as I've read online but if I do so, I won't be able to control the place of an item on the list. I hope I'm more clear this time. Welcoming any response.
Thank you.

推荐答案

您可以继承BaseAdapter和利用以下方法:

You can subclass BaseAdapter and utilize the following methods:

getItemViewType(INT位置)

getViewTypeCount()

getViewTypeCount()应该返回您的适配器支持不同的行类型的数量。 getItemViewType()是贯彻落实决定哪个角度键入一个特定的行应该有。如果,例如, getViewTypeCount()返回3,那么 getItemViewType()方法应该返回0,1,或2

getViewTypeCount() should return the number of different row types your adapter supports. getItemViewType() is where you implement the "decision" of which view type a particular row should have. If, for example, getViewTypeCount() returns 3, then getItemViewType() method should return 0, 1, or 2.

您可以使用此getView内充气/创建不同的行类型不同的布局。

You can use this inside of getView to inflate/create a different layout for different row types.

编辑:

因为它是一个自定义适配器,可以实现它以任何方式适合您的数据。如果你可以创建一个数据结构,你想要的东西的工作,那么就使适配器能够与合作。在最坏的情况下,你可能只是对象的数组(或列表),并且必须使用的instanceof 做决定的工作。

Since it's a custom adapter, you can implement it in whatever way makes sense for your data. If you can create a data structure that works for what you want, then just make the adapter able to work with that. In the worst case, you might just have an array (or list) of Objects and have to use instanceof to do the decision work.

这篇关于Android的 - 的ListView适配器,带的两个视图项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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