ListView的适配器与多个项目布局 [英] ListView Adapter with multiple Item layouts

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

问题描述

我期待在添加一个ListView我有一个缩略图的Andr​​oid应用程序。在左侧和文本右侧的缩略图

I'm looking at adding a listview to my Android application with a thumbnail image. The thumbnail on the left and text on the right.

是否有填充有独立的XML文件列表视图,例如什么办法,我可以有奥地利,英国,美国等独立的XML,并把它们添加到ListView?

Is there any way of populating the list view with seperate xml files, for example, could I have separate xmls for Austria, UK, USA etc and add them to the listview?

我想问的原因是,我打算多次重复使用的个别国家,如,按洲等显示在A到Z,但话又说回来。

The reason I ask is, I plan to reuse the individual countries multiple times, as in, shown in an A to Z but then again by Continent etc.

如果这是可能的,我能得到的如何做到这一点的例子或教程链接等?

If this is possible, could I get an example of how this is done or a link with a tutorial etc?

感谢

推荐答案

你真的要分开.xml文件?或者你想重用1 .xml文件,并只需更换它的内容?

Do you really want separate .xml files? Or do you want to reuse one .xml file and just replace its content?

如果你想单独.xml文件(这意​​味着您的适配器多种不同的意见)
看看适配器方法:

If you want separate .xml files (meaning multiple different Views in your Adapter) take a look at the Adapters methods:


  • getViewTypeCount() - 回报你多少不同的视图布局有

  • getItemViewType(INT POS) - 返回正确按位置视图类型标识

使用这些方法,你可以在你的适配器指定不同类型的数量,并根据不同的类型的加载不同的布局文件。

With these methods you can specify the number of different types in your adapter, and load different layout files depending on the type.

例如,你可以有这样的支持多种布局的适配器。 (例如,一个项目是一个实际的项目时,另一个是在项之间的分离器)

You could for example have an Adapter like this supporting multiple layouts. (e.g. one item being an actual item, the other one being a separator between the items)

有关更多详细信息,请看看这个伟大的教程:

http://android.amberfog.com/?p=296

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

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