如何在 Android 中更改列表视图第一个内容的 属性
How to change the property of first content of List View in Android
我创建了一个可扩展的 listView
并排显示文本的地方我更可能想在那里显示一个 table 的 2 列。为此,我使用了可扩展列表视图,到目前为止它看起来像这样(下图)。
但我想更改此列表第一行的颜色。像这样的东西(下图)。
至于代码,我在水平 Linear Layout
中使用了两个文本视图,并使用自定义适配器在视图中显示数据。这是 XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:text="item"/>
<TextView
android:id="@+id/itemText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:text="Item2"/>
</LinearLayout>
任何人都可以建议我应该怎么做才能实现这一目标?
如果位置 = 0,在你的适配器中
itemText.setBackgroundColor(int colour);
另外你应该使用 RecyclerView 而不是 ListView
我创建了一个可扩展的 listView
并排显示文本的地方我更可能想在那里显示一个 table 的 2 列。为此,我使用了可扩展列表视图,到目前为止它看起来像这样(下图)。
但我想更改此列表第一行的颜色。像这样的东西(下图)。
至于代码,我在水平 Linear Layout
中使用了两个文本视图,并使用自定义适配器在视图中显示数据。这是 XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:text="item"/>
<TextView
android:id="@+id/itemText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:text="Item2"/>
</LinearLayout>
任何人都可以建议我应该怎么做才能实现这一目标?
如果位置 = 0,在你的适配器中
itemText.setBackgroundColor(int colour);
另外你应该使用 RecyclerView 而不是 ListView