【问题标题】:android SimpleCursorAdapter no item msgandroid SimpleCursorAdapter 没有项目消息
【发布时间】:2011-04-13 06:03:13
【问题描述】:

我已经习惯了以下代码来显示最喜欢的项目列表。它具有通过上下文菜单删除的功能。

@Override
    public void onCreate(Bundle savedInstanceState) {

    .........................
    .........................

       wordDataHelper = new WordDataHelper(getApplicationContext());
        favCursor  = wordDataHelper.getCursorFav();
        startManagingCursor(favCursor);
        // Now create a new list adapter bound to the cursor.
        // SimpleListAdapter is designed for binding to a Cursor.
        favAdapter = new SimpleCursorAdapter(
                this, // Context.
                android.R.layout.simple_list_item_1,
                favCursor,                                              // Pass in the cursor to bind to.
                new String[] {WordDataHelper.ENGWORD},           // Array of cursor columns to bind to.
                new int[] {android.R.id.text1});  // Parallel array of which template objects to bind to those columns.

        // Bind to our new adapter.
        setListAdapter(favAdapter);

        list = getListView();


list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
            // @Override
            public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenu.ContextMenuInfo menuInfo) {
                menu.setHeaderTitle("Context Menu");
                menu.add(0, CONTEXT_DELETE, 1, "Delete Item");
            }
        });

        list.setTextFilterEnabled(true);

        list.setClickable(true);

        ..................
    ..................
}

public boolean onContextItemSelected(MenuItem item) {

        AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item
                .getMenuInfo();
        final Long wordId = menuInfo.id;
        // selected_row = menuInfo.position;

        // To get the id of the clicked item in the list use menuInfo.id
        switch (item.getItemId()) {
        case CONTEXT_DELETE:
            deleteRes(wordId);
            favCursor  = wordDataHelper.getCursorFav();
            ((SimpleCursorAdapter) favAdapter).changeCursor(favCursor);
            break;
        default:
            return super.onContextItemSelected(item);

        }


        return true;
    }

一切正常。现在我想在没有要列出的项目时显示“没有最喜欢的项目”消息。怎么安排?

【问题讨论】:

    标签: android listings simplecursoradapter


    【解决方案1】:

    【讨论】:

    • 我添加了 list = getListView(); View empty = (View) findViewById(R.layout.empty); list.setEmptyView(empty);其中 schemas.android.com/apk/res/android" android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize= "18sp" android:textStyle="bold" android:background="#FFFFFF" android:text="@string/empty_fav" android:gravity="center_vertical" android:paddingLeft="6dip" /> 但什么也没有出现。什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 2013-10-26
    • 2014-08-26
    相关资源
    最近更新 更多