【问题标题】:Refresh the listview in fragment android刷新片段android中的listview
【发布时间】:2014-05-22 15:14:09
【问题描述】:

我在左侧片段中有一个列表视图,在右侧有一个动态片段。如果更改是右侧视图中的更新。我想刷新列表视图左侧片段。如何实现这一点。

任何帮助将不胜感激:)

【问题讨论】:

  • 我在片段 A 中有一个包含名称和计数的列表视图。我在片段 B 中有另一个列表视图。如果片段 B 中的项目数增加,那么左侧片段 A 中的计数也应该增加。为此,我需要在片段 a 中重新加载列表视图。
  • 我让你发布你的代码不是为了解释。描述不足以提供解决方案
  • 你检查了 adapter.notifyDataSetChanged(); 吗?
  • @praveenSharma 我试过我需要从片段 B 调用它。所以没有使用 notifyDataSetChanged()
  • @GrIsHu 我无法发布我的代码。请给出理解我的描述的解决方案。

标签: android listview fragment


【解决方案1】:

在我的例子中,OnCreate 片段如下所示:

private MySQLiteHelper      databaseHelper;
private Cursor              c;
private myCursorAdapter     cursorDataAdapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle  savedInstanceState) {

                ViewContext = rootView.getContext();

                databaseHelper = new MySQLiteHelper(ViewContext);
                c = databaseHelper.myquery();
...
}

为了更新我从另一个片段调用的列表视图,在包含列表视图的片段中定义了一个更新函数:

public void updatelistview()
{
    Cursor c = databaseHelper.myquery();
    connettiDataAdapter.changeCursor(c);
    connettiDataAdapter.notifyDataSetChanged();
});

【讨论】:

    【解决方案2】:

    希望对您有所帮助:-

    ListView list = (ListView) getActivity().findViewById(R.id.theIdOfTheList);
    ((BaseAdapter)list.getAdapter()).notifyDataSetChanged();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 2018-01-13
      • 1970-01-01
      相关资源
      最近更新 更多