我在Fragment
中創建ListView
並使用SimpleAdapter
設置佈局和值。更改ListView佈局背景顏色取決於特殊條件
現在我要在ListView
中使用的佈局中的LinearLayout
的背景依據爲ListView
設置的文本來更改背景。
事情是這樣的:
這是我的佈局XML。
我想用list
id改變LinearLayout的顏色。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="@drawable/layout_shadow"
android:layout_height="207dp">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:layout_height="193dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:id="@+id/list">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="magnitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fValue"
android:textStyle="bold"
android:textColor="@android:color/white"
android:textSize="20sp"
android:layout_margin="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="region"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/sValue"
android:textColor="@android:color/white" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
app:srcCompat="@drawable/no_image"
android:id="@+id/mImage"
android:layout_height="143dp" />
</LinearLayout>
</RelativeLayout>
在適配器中,檢查爲了positio並改變佈局的顏色。像,如果位置== 0 Color.RED,位置== 1 COLOR.BLUE –
@Divyesh謝謝,但我想改變它取決於textView中的文本。但是你說什麼改變取決於立場。 –
然後使用每個位置的文本值進行更改。 –