代码之家  ›  专栏  ›  技术社区  ›  Matty F

ListAdapters和WrapperListAdapter算法

  •  0
  • Matty F  · 技术社区  · 16 年前

    这个逻辑写在一个带有签名的函数中

    private void showDialog(final AdapterView<? extends Adapter> parent,
         String title, String message, final Tag subject)
    

    有没有更好的办法?

    // refresh adapter
    SimpleCursorAdapter adapter;
    if (parent.getAdapter() instanceof WrapperListAdapter) {
        adapter = (SimpleCursorAdapter) ((WrapperListAdapter) parent.getAdapter()).getWrappedAdapter();
    } else {
        adapter = (SimpleCursorAdapter) parent.getAdapter();
    }
    adapter.getCursor().requery();
    adapter.notifyDataSetChanged();
    

    还有,有什么意义吗 AdapterView<? extends Adapter> 在签名上而不仅仅是 AdapterView<?>

    1 回复  |  直到 16 年前
        1
  •  1
  •   CommonsWare    16 年前

    抓住你的手 Cursor 对象和调用 requery()

    另外,理想情况下,您不需要打电话 notifyDataSetChanged() -- CursorAdapter 这是自动的,希望 WrapperListAdapter 并级联 notifyDataSetChanged()

    中的适配器视图

    如果您试图创建 AdapterView Integer ,或 Button ,或 Socket . 换句话说,它增加了一点编译时类型安全性。