简体   繁体   English

包含不同XML标记(RSS)的list_item和single_list_item

[英]list_item and single_list_item containing different XML tags (RSS)

I'm using RSS with different tags for my app and I want to show, for example, <title> and <pubDate> in my List, but when I click on specific item it suppose to open new layout which contains <title> and <description> . 我正在为我的应用程序使用带有不同标签的RSS,并且想在列表中显示例如<title><pubDate> ,但是当我单击特定项目时,它想打开包含<title><title> <description>

I would appreciate any kind of help, link, hint or whatever :) 我将不胜感激任何帮助,链接,提示或其他任何方式:)

Thanks 谢谢

ListViews are tricker. ListViews是骗人的。 The ListAdapter you use has to specify a layout that describes a single entry in the list, the source data items, and for each item the destination View in the single entry layout. 您使用的ListAdapter必须指定一个布局,该布局描述列表中的单个条目,源数据项以及每个条目的目标视图。 There has to be a one-to-one correspondence between source item and destination View. 源项目和目标视图之间必须存在一对一的对应关系。 HOWEVER, the array/Cursor/whatever that contains the source data can have more data in it. 但是,数组/光标/ 包含源数据的任何内容都可以包含更多数据。 For a SimpleCursorAdapter, for instance, the Cursor itself can contain 15 items, but you only have to show 2. For a SimpleCursorAdapter, source items are specified as column names in an array of String, and destination Views are specified as resourceIDs in an array of int. 例如,对于SimpleCursorAdapter,Cursor本身可以包含15个项目,但您只需要显示2。对于SimpleCursorAdapter,将源项目指定为String数组中的列名,并将目标视图指定为数组中的resourceIDs。的int。

The most friendly way to display the details of a single list entry is to have an onClickListener that opens a new Activity/Fragment when clicked. 显示单个列表条目的详细信息的最友好方法是让onClickListener在单击时打开一个新的Activity / Fragment。 The Listener is passed the index of the entry that was clicked. 向侦听器传递单击的条目的索引。 From this, you can work back to the Cursor row that backs that entry, then pass the necessary data to the new Activity/Fragment. 由此,您可以返回到支持该条目的Cursor行,然后将必要的数据传递给新的Activity / Fragment。

I used Cursor because that's the most common use case, but the same pattern works for arrays, lists, etc. 我使用Cursor是因为这是最常见的用例,但是相同的模式适用于数组,列表等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM