【问题标题】:How to override or add custom layout to android.R.layout.simple_list_item_activated_1如何覆盖或添加自定义布局到 android.R.layout.simple_list_item_activated_1
【发布时间】:2014-11-20 18:53:29
【问题描述】:

我正在设置一个列表适配器,如下所示,如果我只是将 simple_list_item_activated_1 更改为 lv_layout 它根本不起作用。

有什么想法吗?

谢谢!

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(
            getActivity(),
            android.R.layout.simple_list_item_activated_1,
            android.R.id.text1,
            DummyContent.ITEMS));
}

如何将名为 lv_layout 的自定义布局附加到该适配器?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/lv_layout"

    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/flag"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="10dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/size"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/resolution"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp" />

    </LinearLayout>

</LinearLayout>

【问题讨论】:

    标签: android android-layout android-fragments android-listfragment


    【解决方案1】:

    那你为什么要使用 setlistadapter 呢?在这种情况下,您也必须创建自定义适配器,因为 serlistapater 只会更新自定义布局的 textview 部分,而其余部分将忽略哪个 idont 认为您想要什么。所以 1.制作自定义适配器 2.覆盖它的getview 3.将适配器设置为您的自定义布局。 干杯

    【讨论】:

      【解决方案2】:

      android.R.* 是 Android 的内部资源。

      要使用来自 res/layout/ 的您自己的布局,请跳过 android 前缀:

      R.layout.lv_layout
      

      ID 也是如此(如果您想知道的话)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多