在布局动态更改时通知ListView

时间:2011-10-07 06:18:02

标签: android android-layout android-listview

我有一个ListView:

SimpleAdapter adapter = new SimpleAdapter(
                        getApplicationContext(), forecastList,
                        R.layout.weather_list_row, new String[] { "forecast",
                                "precipitation", "temperature" }, new int[] {
                                R.id.forecast, R.id.precipitation,
                                R.id.temperature });
                lv1.setAdapter(adapter);

我有一个“ R.layout.weather_list_row ”:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="4dip" android:paddingBottom="6dip"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView android:id="@+id/forecast" android:layout_width="150dip"
        android:layout_height="wrap_content" android:textColor="#000000" />

    <LinearLayout android:layout_height="wrap_content"
        android:layout_weight="1" android:layout_width="50dip">
        <TextView android:id="@+id/precipitation"
            android:layout_width="wrap_content" android:textColor="#00357A"
            android:layout_height="wrap_content" />
        <ImageView android:layout_height="wrap_content" android:id="@+id/weather_status1"
            android:layout_width="wrap_content" />
    </LinearLayout>

    <LinearLayout android:layout_height="wrap_content"
        android:layout_weight="1" android:layout_width="50dip">
        <TextView android:id="@+id/temperature" android:layout_width="wrap_content"
            android:textColor="#00357A" android:layout_height="wrap_content" />
        <ImageView android:layout_height="wrap_content" android:id="@+id/weather_status2"
            android:layout_width="wrap_content" />
    </LinearLayout>
</LinearLayout>

R.layout.weather_list_row 中,我正在动态更改 ImageView src =

  • 问题:当我更改时,如何通知ListView R.layout.weather_list_row?
  • 中的值

1 个答案:

答案 0 :(得分:2)

尝试adapter.notifyDataSetChanged();