android - 通知 ListView 布局动态变化

标签 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 中,我正在动态更改 ImageViewsrc=

  • 问题:当我更改 R.layout.weather_list_row 中的值?

最佳答案

试试 adapter.notifyDataSetChanged();

关于android - 通知 ListView 布局动态变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7683677/

相关文章:

java - 出现异常如何解决

单击 View 时触发事件的android事件处理程序

android - 带有可折叠工具栏的 WebView? ( Material 设计)

android - 如何将可点击按钮添加到当前可点击的 TextView

android - Android 2.3.3 上的 ListView 页脚背景

Android ListView - 更新时滚动回到顶部

android - 使用SQLiteOpenHelper在数据库中创建表时,应用程序崩溃

android - onConfigurationChanged 不去监听

android - 保存 ListView 滚动位置并在返回时恢复该位置

android - 强制 ListViews 上的 Android 快速滚动条在填充内绘制