【发布时间】:2016-02-18 13:34:49
【问题描述】:
我有一个数据结构,其类型为:
ArrayList<ArrayList<String>>;
...它包含一组新闻提要的元素;每个元素本身就是一个字段列表,每个字段都是一个元组(键:值),其中键和值都是字符串类型。
注意:字段存储在 ArrayList 中的原因是我并不总是知道提要解析器会喷出多少。
观点:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/news"
android:text="@string/news_and_events"
android:layout_row="6"
android:layout_column="4"
android:layout_columnSpan="3"
android:layout_rowSpan="3"
android:width="180dp"
android:height="245dp"
android:layout_marginBottom="10dp">
<!--FEED-->
<ListView
android:id="@android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</RelativeLayout>
我要使用的行模板是:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="@+id/picture"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="6dip"
android:contentDescription=""
/>
<!--STARTING WITH title-->
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/picture"
android:ellipsize="marquee"
android:singleLine="true"
android:text=""
android:textSize="20sp"
/>
<TextView
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
如您所见,有 3 个字段:标题、正文、图像(新闻提要)。
所以我完全不知道应该使用哪种类型的适配器。 我看过的所有东西似乎都与我想做的不符;特别是因为我使用的数据结构。
也许我应该使用光标适配器? 如果是这样,我将如何将其映射到关系数据库中?!
【问题讨论】:
-
我建议您实现自己的适配器。这并不难。看看developer.android.com/reference/android/widget/BaseAdapter.html 那里有很多例子,如何实现自定义适配器。
-
从 ArrayAdapter 继承,让数据层解析你的对象,而不是 UI。
标签: android list arraylist adapter feed