【问题标题】:Refresh Listadapter with custom listview in Listfragment android在 Listfragment android 中使用自定义列表视图刷新 Listadapter
【发布时间】:2015-03-30 11:00:40
【问题描述】:

我使用列表适配器为列表视图设置值。这些值是从 web 服务 api 加载的。我需要如何在 android 中使用列表适配器刷新自定义的列表视图。

【问题讨论】:

    标签: android listview customization android-listfragment listadapter


    【解决方案1】:

    有两种方法可以做到这一点:

    1. 每次重新加载数据时,创建一个新适配器并将其设置为带有setAdapter 的 ListView。
    2. 重用适配器(通过setData或类似方法)并在此之后调用notifyDataSetChanged,从而刷新视图。

    【讨论】:

    • 对于 listadapter 没有 notifydatasetchanged 方法来刷新列表视图。
    • notifyDataSetChangedArrayAdapter 中。你的适配器会扩展它吗?
    • 任何人请告诉我如何使用自定义布局从列表视图中删除所有项目??
    • 尝试将适配器设置为null:yourlistview.setAdapter(null)
    • @junanjo Vega 在 listfragment 中没有像 notifydatasetchanged 这样的 listview 方法...
    【解决方案2】:

    您需要使用适配器中的 notifyDataSetChanged(),为了做到这一点,您的适配器需要扩展 BaseAdapter,因此每次更改一些数据时,都会调用 ,

    instanceOfAdaper.notifyDataSetChanged()
    

    【讨论】:

    • ListAdapter adapter1 = new SimpleAdapter( getActivity(), entriesList1, R.layout.new_todo_single, new String[] { "id","date","message","status"}, new int [] { R.id.todo_id,R.id.todo_date,R.id.todo_message,R.id.todo_status}); // setListAdapter(null); // 更新列表视图 setListAdapter(adapter1);
    • 这是我的适配器..它在 listfragment 中,所以没有 notifydatasetchanged method()..我使用自定义列表视图和 ArrayList>
    • 据我了解,您想更改刷新列表视图中的一些数据吗?因此,您需要捕捉位置、需要更改的内容、操作然后使用 adapter1.notifyDataSetChanged();跨度>
    • 你需要在activity中调用notifyDataSetChanged()。
    • 我正在使用 Listfragment 而不是活动...删除或编辑项目后我需要刷新我的列表视图
    【解决方案3】:

    我猜你一定是使用AsyncTask方法从WebService中获取数据,重写这个方法,然后像这样在onPostExecute中调用notifyDataSetChanged方法。

    protected void onPostExecute(String result) {
        adapter.notifyDataSetChanged();             
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-11
      相关资源
      最近更新 更多