1

我仍在学习在 Android 中进行瘦身的最佳方法,但我有一个无法解决的问题。我试图理解几个小时,试图找到工作片段,但我无法完成这项工作。

我创建了一个 ContentProvider 来封装数据库访问(我知道我可以在没有 ContentProviders 的情况下做到这一点,但我想学习 :))。

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(android.R.layout.simple_list_item_activated_1, container, false);
    String[] projection = { CustomerDatabaseHelper.Col_name };
    int[] uiBindTo = { android.R.id.text1 };

    Cursor cursor = getActivity().getContentResolver().query(CustomerContentProvider.CONTENT_URI,
            projection, null, null, null); // CustomerDatabaseHelper.Col_name+" ASC"
    getLoaderManager().initLoader(CUSTOMER_LIST_LOADER, null, this);
    adapter = new SimpleCursorAdapter(
            getActivity().getApplicationContext(),
            android.R.layout.simple_list_item_activated_1, cursor,
            projection, uiBindTo,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    setListAdapter(adapter);
    return view;
}

如果我在游标参数中输入 null ,它可以工作,但不会为我提供排序的列表。我创建了光标来对我的列表进行排序。当我将它放入参数时,应用程序崩溃并显示以下消息:java.lang.RuntimeException:无法启动活动 ComponentInfo{pt.com.hugodias.hstreportmanager/pt.com.hugodias.hstreportmanager.customer.CustomerListActivity}:android。 view.InflateException:二进制 XML 文件第 24 行:膨胀类片段时出错

我希望有人能帮助我。

雨果

4

0 回答 0