【问题标题】:Adapter for data-biding on gridviewgridview 中数据绑定的适配器
【发布时间】:2014-08-12 15:31:09
【问题描述】:

我有一个网格视图

<GridView
    android:id="@+id/gridViewProduit"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:numColumns="3" >
</GridView>

并且我已将该 GridView 与以下布局绑定:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >
         <TextView
            android:id="@+id/hdn_txt_code"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <TextView
            android:id="@+id/txv_des"
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_gravity="center"
            android:layout_height="wrap_content" />

       </LinearLayout>

为此,我使用了这样的 SimpleAdapter:

 SimpleAdapter   produitAdapter = new SimpleAdapter(this.getBaseContext(),
                    familleItem, R.layout.affiche_famille_produit, new String[] {
                            "CODE", "DESIGNATION" }, new int[] { R.id.hdn_txt_code,
                            R.id.txv_des });

我需要多次刷新这个gridview,在SimpleAdapter的文档中说这个Adapter是用于静态数据的,这不是我的情况。 我正在寻找一个允许我在我的 gridview 上绑定我的日期的适配器,比如 SimpleAdapter 允许我。 谢谢

【问题讨论】:

    标签: android data-binding mapping android-gridview android-adapter


    【解决方案1】:

    如果适配器中的数据发生变化,那么您只需在适配器上调用notifyDataSetChanged,网格就会重新填充

    【讨论】:

    • 我调用了它,但它似乎不适用于 simpleAdapter。正如我所说,SimpleAdapter 推荐用于静态数据,在我的情况下它不是静态的。
    • 是创建costum adapter 的解决方案吗?
    【解决方案2】:

    我认为解决方案是覆盖 ArrayAdapter 并在 getView 方法上绑定数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-27
      • 2017-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多