0

如何刷新微调器的数据集?这是我的代码:

mCategory = (Spinner) rootView.findViewById(R.id.detail_categoryType);
    String[] mCategoryProjection = { DailyTables.TABLE_CATEGORIES_COLUMN_ID, DailyTables.TABLE_CATEGORIES_COLUMN_TITLE };
    int[] to = new int[] {  android.R.id.text1, android.R.id.text1 };
    Cursor mCategoryCursor = getActivity().getContentResolver().query(DailyContentProvider.CATEGORIES_CONTENT_URI, mCategoryProjection, null, null, null);
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_item, mCategoryCursor, mCategoryProjection, to, 0 );
    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    mCategory.setAdapter(adapter);
    mCategory.setOnLongClickListener(new AdapterView.OnLongClickListener() { 
        public boolean onLongClick(View v) { 
            Cursor currentItem = (Cursor) mCategory.getSelectedItem();
            if( currentItem != null ) {
                 Log.d("", currentItem.getString(currentItem.getColumnIndexOrThrow(DailyTables.TABLE_CATEGORIES_COLUMN_TITLE)) + " is long clicked");
                 DialogFragment newFragment = SpinnerEditCategoryDialogFragment.newInstance( currentItem.getInt(currentItem.getColumnIndexOrThrow(DailyTables.TABLE_CATEGORIES_COLUMN_ID)) );
                 newFragment.show(getActivity().getSupportFragmentManager(), "dialog");
            }
            ((SimpleCursorAdapter) mCategory.getAdapter()).notifyDataSetChanged();
            return true; 
        } 
     }); 

如果我长按微调器,则会打开一个对话框,该对话框会重命名微调器中的项目。因此,如果它能显示正确的值,那就太好了。 notifyDataSetChanged()不做这项工作。怎么了?

4

0 回答 0