【问题标题】:I'm completely stumped as to which Android Adapter to inherit/use我完全不知道继承/使用哪个 Android 适配器
【发布时间】: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 个字段:标题、正文、图像(新闻提要)。

所以我完全不知道应该使用哪种类型的适配器。 我看过的所有东西似乎都与我想做的不符;特别是因为我使用的数据结构。

也许我应该使用光标适配器? 如果是这样,我将如何将其映射到关系数据库中?!

【问题讨论】:

标签: android list arraylist adapter feed


【解决方案1】:

我认为您应该尝试使用BaseAdapter,它是 Android 拥有的最灵活的适配器(我认为)... 通过这样做,您可以实现一个自定义适配器,它通过ArrayList(使用 2 个周期进行提取),然后将其解析为您指定的可视组件。 由于它的构造函数接收上下文、视图和数据,因此您将拥有ImageView 等等。

【讨论】:

  • 我不知道为什么这被否决了,但我同意应该使用BaseAdapter。它在数据源方面也很灵活,因此可以根据需要将其更改为从数据库中提取,而不是始终依赖ArrayList
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-26
  • 1970-01-01
相关资源
最近更新 更多