Java 类android.support.v4.widget.CursorAdapter 实例源码

项目:Android-pH2Note-App    文件:MainActivity.java   
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    addNote(DEFAULT_NOTE_TITLE);

    Cursor cursor = getContentResolver().query(NoteProvider.CONTENT_URI, DBOpenHelper.ALL_COLUMNS, null, null, null, null);
    String[] from = {DBOpenHelper.NOTE_TEXT};
    int[] to  = {android.R.id.text1};
    CursorAdapter cursorAdapter = new SimpleCursorAdapter(this, android.R.simple_list_item1, cursor, from, to, 0);

    ListView list = (ListView) findViewById(android.R.id.list);
    list.setAdapter(cursorAdapter);
}
项目:privacy-friendly-notes    文件:RecycleActivity.java   
private void deleteAll(){
    ListView notesList = (ListView) findViewById(R.id.notes_list);
    CursorAdapter ca = (CursorAdapter) notesList.getAdapter();
    Cursor c = ca.getCursor();
    c.moveToPosition(-1);
    while (c.moveToNext()){
        if (c.getInt(c.getColumnIndexOrThrow(DbContract.NoteEntry.COLUMN_TYPE)) == DbContract.NoteEntry.TYPE_AUDIO) {
            String filePath = getFilesDir().getPath()+"/audio_notes" + c.getString(c.getColumnIndexOrThrow(DbContract.NoteEntry.COLUMN_CONTENT));
            new File(filePath).delete();
        } else if (c.getInt(c.getColumnIndexOrThrow(DbContract.NoteEntry.COLUMN_TYPE)) == DbContract.NoteEntry.TYPE_SKETCH) {
            String content = c.getString(c.getColumnIndexOrThrow(DbContract.NoteEntry.COLUMN_CONTENT));
            new File(getFilesDir().getPath()+"/sketches"+content).delete();
            new File(getFilesDir().getPath()+"/sketches"+content.substring(0, content.length()-3) + "jpg").delete();
        }
        DbAccess.deleteNote(getBaseContext(), c.getInt(c.getColumnIndexOrThrow(DbContract.NoteEntry.COLUMN_ID)));
    }
    updateList();
}
项目:devbricks    文件:AbsCursorAdapterFragment.java   
@Override
protected void bindAdapterView() {
    final ListAdapter oldAdapter = getAdapter();

    Cursor oldCursor = null;

    if (oldAdapter instanceof CursorAdapter) {
        oldCursor = ((CursorAdapter)oldAdapter).getCursor();
    }

    super.bindAdapterView();

    if (oldCursor != null) {
        swapCursor(oldCursor);
    }
}
项目:SyncFrameworkAndroid    文件:AdapterViewHelper.java   
public static boolean setSelectionById(final AdapterView spinner, final boolean loaded, long id, final String columnName, boolean setLastIfDidntFind) {
    if (loaded && id != AdapterView.INVALID_ROW_ID) {
        Cursor c = ((CursorAdapter) spinner.getAdapter()).getCursor();
        if (c != null) {
            int pos = 0;
            if (c.moveToFirst()) {
                final int index = c.getColumnIndex(columnName);
                do {
                    if (c.getLong(index) == id) {
                        spinner.setSelection(pos);
                        return true;
                    }
                    pos++;
                } while (c.moveToNext());
                if(setLastIfDidntFind) {
                    spinner.setSelection(--pos);
                }
            }
        }
    }
    return false;
}
项目:SyncFrameworkAndroid    文件:AdapterViewHelper.java   
public static boolean setSelectionByValue(final AdapterView spinner, final boolean loaded, String value, final String columnName, boolean setLastIfDidntFind) {
    if (loaded && value != null) {
        Cursor c = ((CursorAdapter) spinner.getAdapter()).getCursor();
        if (c != null) {
            int pos = 0;
            if (c.moveToFirst()) {
                value = value.toLowerCase();
                final int index = c.getColumnIndex(columnName);
                do {
                    if (c.getString(index).toLowerCase().equals(value)) {
                        spinner.setSelection(pos);
                        return true;
                    }
                    pos++;
                } while (c.moveToNext());
                if(setLastIfDidntFind) {
                    spinner.setSelection(--pos);
                }
            }
        }
    }
    return false;
}
项目:Android_ApplicationTemplate    文件:ListFrag.java   
private void populateList() {

        String[] from = null;
        if (isFav) {
            from = new String[] { Beans.Favorite.COL_TITLE };
        } else {
            from = new String[] { Beans.Category.COL_NAME };
        } //check if fav or list
        int[] to = { R.id.list_item_text };
        int layoutId = R.layout.list_item;
        if (Preferences.getInstance(getActivity()).isRTL())
            layoutId = R.layout.list_item_right;

        getLoaderManager().initLoader(1, null, this);
        adapter = new SimpleCursorAdapter(getActivity(), layoutId, null, from,
                to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        adapter.setViewBinder(new Binder());
        setListAdapter(adapter);
        adapter.notifyDataSetChanged();
    }
项目:javaide    文件:LogcatActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_logcat);

    LogLine.isScrubberEnabled = PreferenceHelper.isScrubberEnabled(this);

    handleShortcuts(getIntent().getStringExtra("shortcut_action"));

    mHandler = new Handler(Looper.getMainLooper());

    binding.fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogHelper.stopRecordingLog(LogcatActivity.this);
        }
    });

    binding.list.setLayoutManager(new LinearLayoutManager(this));

    binding.list.setItemAnimator(null);

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar_actionbar));
    setTitle(R.string.logcat);

    mCollapsedMode = !PreferenceHelper.getExpandedByDefaultPreference(this);

    log.d("initial collapsed mode is %s", mCollapsedMode);

    mSearchSuggestionsAdapter = new SimpleCursorAdapter(this,
            R.layout.list_item_dropdown,
            null,
            new String[]{"suggestion"},
            new int[]{android.R.id.text1},
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    setUpAdapter();
    updateBackgroundColor();
    runUpdatesIfNecessaryAndShowWelcomeMessage();
}
项目:intra42    文件:SuperSearch.java   
public static SimpleCursorAdapter setSearchSuggestionAdapter(Context context) {
    final String[] from = new String[]{"name"};
    final int[] to = new int[]{android.R.id.text1};
    SimpleCursorAdapter searchAdapter = new SimpleCursorAdapter(context, android.R.layout.simple_list_item_1, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);


    final MatrixCursor c = new MatrixCursor(new String[]{BaseColumns._ID, "name"});
    for (int i = 0; i < SuperSearch.suggestions.length; i++) {
        c.addRow(new Object[]{i, SuperSearch.suggestions[i]});
    }
    searchAdapter.changeCursor(c);

    return searchAdapter;
}
项目:libcommon    文件:MediaStoreAdapter.java   
public MediaStoreAdapter(final Context context, final int id_layout) {
    super(context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mInflater = LayoutInflater.from(context);
    mCr = context.getContentResolver();
    mQueryHandler = new MyAsyncQueryHandler(mCr, this);
    // getMemoryClass return the available memory amounts for app as mega bytes(API >= 5)
    mMemClass = ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    mLayoutId = id_layout;
    onContentChanged();
}
项目:truth-android    文件:CursorAdapterSubject.java   
public static SubjectFactory<CursorAdapterSubject, CursorAdapter> type() {
  return new SubjectFactory<CursorAdapterSubject, CursorAdapter>() {
    @Override
    public CursorAdapterSubject getSubject(FailureStrategy fs, CursorAdapter that) {
      return new CursorAdapterSubject(fs, that);
    }
  };
}
项目:TextSecure    文件:PushContactSelectionListFragment.java   
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
  ((CursorAdapter) listView.getAdapter()).changeCursor(data);
  emptyText.setText(R.string.contact_selection_group_activity__no_contacts);
  if (data != null && data.getCount() < 40) listView.setFastScrollAlwaysVisible(false);
  else                                      listView.setFastScrollAlwaysVisible(true);
}
项目:yield    文件:CalendarSelectionView.java   
public CalendarCursorAdapter(Context context) {
    super(context,
            R.layout.list_item_calendar,
            null,
            new String[]{CalendarContract.Calendars.CALENDAR_DISPLAY_NAME},
            new int[]{R.id.text_view_title},
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
}
项目:openshop.io-android    文件:MainActivity.java   
@Override
public void prepareSearchSuggestions(List<DrawerItemCategory> navigation) {
    final String[] from = new String[]{"categories"};
    final int[] to = new int[]{android.R.id.text1};

    searchSuggestionsAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1,
            null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    if (navigation != null && !navigation.isEmpty()) {
        for (int i = 0; i < navigation.size(); i++) {
            if (!searchSuggestionsList.contains(navigation.get(i).getName())) {
                searchSuggestionsList.add(navigation.get(i).getName());
            }

            if (navigation.get(i).hasChildren()) {
                for (int j = 0; j < navigation.get(i).getChildren().size(); j++) {
                    if (!searchSuggestionsList.contains(navigation.get(i).getChildren().get(j).getName())) {
                        searchSuggestionsList.add(navigation.get(i).getChildren().get(j).getName());
                    }
                }
            }
        }
        searchSuggestionsAdapter.notifyDataSetChanged();
    } else {
        Timber.e("Search suggestions loading failed.");
        searchSuggestionsAdapter = null;
    }
}
项目:privacy-friendly-notes    文件:MainActivity.java   
private void deleteSelectedItems(){
    ListView notesList = (ListView) findViewById(R.id.notes_list);
    CursorAdapter adapter = (CursorAdapter) notesList.getAdapter();
    SparseBooleanArray checkedItemPositions = notesList.getCheckedItemPositions();
    for (int i=0; i < checkedItemPositions.size(); i++) {
        if(checkedItemPositions.valueAt(i)) {
            DbAccess.trashNote(getBaseContext(), (int) (long) adapter.getItemId(checkedItemPositions.keyAt(i)));
        }
    }
}
项目:privacy-friendly-notes    文件:RecycleActivity.java   
private void updateList() {
    ListView notesList = (ListView) findViewById(R.id.notes_list);
    CursorAdapter adapter = (CursorAdapter) notesList.getAdapter();
    String selection = DbContract.NoteEntry.COLUMN_TRASH + " = ?";
    String[] selectionArgs = { "1" };
    adapter.changeCursor(DbAccess.getCursorAllNotes(getBaseContext(), selection, selectionArgs));
}
项目:privacy-friendly-notes    文件:ManageCategoriesActivity.java   
private void deleteItem(int position) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    boolean delNotes = sp.getBoolean(SettingsActivity.PREF_DEL_NOTES, false);
    CursorAdapter adapter = (CursorAdapter) list.getAdapter();
    if (delNotes) {
        DbAccess.trashNotesByCategoryId(getBaseContext(), (int) (long) adapter.getItemId(position));
    }
    DbAccess.deleteCategory(getBaseContext(), (int) (long) adapter.getItemId(position));
    updateList();
}
项目:privacy-friendly-notes    文件:ManageCategoriesActivity.java   
private void deleteSelectedItems(){
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    boolean delNotes = sp.getBoolean(SettingsActivity.PREF_DEL_NOTES, false);
    CursorAdapter adapter = (CursorAdapter) list.getAdapter();
    SparseBooleanArray checkedItemPositions = list.getCheckedItemPositions();
    for (int i=0; i < checkedItemPositions.size(); i++) {
        if(checkedItemPositions.valueAt(i)) {
            if (delNotes) {
                DbAccess.trashNotesByCategoryId(getBaseContext(), (int) (long) adapter.getItemId(checkedItemPositions.keyAt(i)));
            }
            DbAccess.deleteCategory(getBaseContext(), (int) (long) adapter.getItemId(checkedItemPositions.keyAt(i)));
        }
    }
}
项目:devbricks    文件:AbsCursorAdapterFragment.java   
protected void swapCursor(Cursor c) {
    final BaseAdapter adapter = getAdapter();
    if (adapter instanceof CursorAdapter) {
        Cursor oldCursor = ((CursorAdapter)adapter).swapCursor(c);

        if (oldCursor != null && oldCursor != c) {
            oldCursor.close();
        }
    }
}
项目:matlog    文件:LogcatActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_logcat);

    LogLine.isScrubberEnabled = PreferenceHelper.isScrubberEnabled(this);

    handleShortcuts(getIntent().getStringExtra("shortcut_action"));

    mHandler = new Handler(Looper.getMainLooper());

    binding.fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            DialogHelper.stopRecordingLog(LogcatActivity.this);
        }
    });

    binding.list.setLayoutManager(new LinearLayoutManager(this));

    binding.list.setItemAnimator(null);

    setSupportActionBar(binding.toolbar.toolbarActionbar);

    mCollapsedMode = !PreferenceHelper.getExpandedByDefaultPreference(this);

    log.d("initial collapsed mode is %s", mCollapsedMode);

    mSearchSuggestionsAdapter = new SimpleCursorAdapter(this,
            R.layout.list_item_dropdown,
            null,
            new String[]{"suggestion"},
            new int[]{android.R.id.text1},
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

    setUpAdapter();
    updateBackgroundColor();
    runUpdatesIfNecessaryAndShowWelcomeMessage();
}
项目:colorread    文件:FragmentNews.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // 加载布局
    View view = inflater.inflate(R.layout.fragment_news, null);
    iv_add_chnnel = (ImageView) view.findViewById(R.id.iv_add_chnnel);
    gridView = (GridView) view.findViewById(R.id.news_gridView);
    viewPager = (ViewPager) view.findViewById(R.id.news_viewPager);
    contentResolver = getActivity().getContentResolver();
    Bmob.initialize(getContext(), "7dba48d154a17b9b57e53c413bc889de");

    Bundle bundle = getArguments();
    boolean haveBigNews = bundle.getBoolean("BundleHaveBigNews");

    Pageradapter = new MyPagerAdapter(list);
    viewPager.setAdapter(Pageradapter);
    // 获取图片和连接
    if (haveBigNews) {
        // 从Loading传过来的,也是醉了。
        bigNews = (List<BigNews>) bundle.getSerializable("BigNews");
        ViewPagerSetNewAdapter();
    } else {
        getPagerData();
    }
    getChnnel();
    // adapter
    adapter = new GridViewCursorAdapter(getContext(), chnnelCursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    gridView.setAdapter(adapter);

    // 添加GridViewItem监听
    ItemClick();
    // 添加按钮设置监听事件
    addChnnel();
    // 添加gridV长按监听
    DeleteChnnel();
    // 添加ViewPager监听
    watchBigNews();
    return view;
}
项目:yield    文件:CalendarSelectionView.java   
public CalendarCursorAdapter(Context context) {
    super(context,
            R.layout.list_item_calendar,
            null,
            new String[]{CalendarContract.Calendars.CALENDAR_DISPLAY_NAME},
            new int[]{R.id.text_view_title},
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
}
项目:nc-traffic-cams-open    文件:CameraGalleryFragment.java   
@Override
public void onPostExecute(Object obj) {
    if(obj instanceof Cursor) {
        Cursor cursor = (Cursor) obj;
        try {

            if (mAdapter != null && mAdapter instanceof DefaultCamerasAdapter) {
                ((CursorAdapter) mAdapter).changeCursor(cursor);
            } else {
                mAdapter = new DefaultCamerasAdapter(getActivity(), cursor);
                mAdapterView.setAdapter(mAdapter);
            }

            toggleEmptyGalleryView(mAdapter.getCount() == 0, R.string.no_favorites);
        } catch (IllegalStateException e) {
            Log.e(TAG, e.getMessage());
        }
    } else if (obj instanceof List<?>) {
        @SuppressWarnings("unchecked")
        List<Camera> cameras = (List<Camera>) obj;
        mAdapter = new NearMeCamerasAdapter(getActivity(), cameras);
        mAdapterView.setAdapter(mAdapter);
        ((NearMeCamerasAdapter) mAdapter).notifyDataSetChanged();

        toggleEmptyGalleryView(cameras.size() == 0, R.string.no_cameras_near);
    }
}
项目:downtown    文件:CustomSuggestionsAdapter.java   
public CustomSuggestionsAdapter(Context context, SearchableInfo info, SearchView searchView)
{
    super(context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    this.searchable = info;
    this.searchView = searchView;
    this.inflater = LayoutInflater.from(context);
}
项目:SyncFrameworkAndroid    文件:SpinnerHelper.java   
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (loader.getId() == mLoaderID) {
        ((CursorAdapter) Spinner.getAdapter()).swapCursor(cursor);
        setSelectionByValue(true, mValue, mColumn);
        setSelectionById(true, mId, mColumn);
        mDataLoaded = true;
    }
}
项目:SyncFrameworkAndroid    文件:SpinnerHelper.java   
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    if (loader.getId() == mLoaderID) {
        ((CursorAdapter) Spinner.getAdapter()).swapCursor(null);
        mDataLoaded = false;
    }
}
项目:SyncFrameworkAndroid    文件:ListFragmentCommon.java   
protected void finishLoading(final Cursor data) {
    ((CursorAdapter) getListAdapter()).swapCursor(data);
    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}
项目:arca-android    文件:ArcaSimpleItemSupportFragment.java   
@Override
public CursorAdapter onCreateAdapter(final View view, final Bundle savedInstanceState) {
    final Collection<Binding> bindings = FragmentUtils.getBindings(this.getClass());
    final SupportItemAdapter adapter = new SupportItemAdapter(getActivity(), bindings);
    adapter.setViewBinder(FragmentUtils.createViewBinder(this.getClass()));
    return adapter;
}
项目:arca-android    文件:ArcaAdapterSupportFragment.java   
@SuppressWarnings("unchecked")
private void setupAdapterView(final View view, final Bundle savedInstanceState) {
       mAdapterView = (AdapterView<CursorAdapter>) view.findViewById(getAdapterViewId());

       mAdapter = onCreateAdapter(mAdapterView, savedInstanceState);

       mAdapterView.setAdapter(mAdapter);
}
项目:arca-android    文件:ArcaSimpleAdapterSupportFragment.java   
public CursorAdapter onCreateAdapter(final AdapterView<CursorAdapter> adapterView, final Bundle savedInstanceState) {
    final int layout = FragmentUtils.getAdapterItemLayout(this.getClass());
    final Collection<Binding> bindings = FragmentUtils.getBindings(this.getClass());
    final SupportCursorAdapter adapter = new SupportCursorAdapter(getActivity(), layout, bindings);
    adapter.setViewBinder(FragmentUtils.createViewBinder(this.getClass()));
    return adapter;
}
项目:arca-android    文件:ArcaItemSupportFragment.java   
public void bindViewAtPosition(final int position) {
    final CursorAdapter adapter = getCursorAdapter();
    final Cursor cursor = adapter.getCursor();
    if (cursor != null && cursor.moveToPosition(position)) {
        adapter.bindView(getView(), getActivity(), cursor);
    }
}
项目:android-money-manager-ex    文件:BaseReportFragment.java   
@Override
    public void onLoaderReset(Loader<Cursor> loader) {
        switch (loader.getId()) {
            case ID_LOADER:
//                ((CursorAdapter) getListAdapter()).swapCursor(null);
                ((CursorAdapter) getListAdapter()).changeCursor(null);
        }
    }
项目:android-money-manager-ex    文件:BaseReportFragment.java   
@Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        switch (loader.getId()) {
            case ID_LOADER:
//                ((CursorAdapter) getListAdapter()).swapCursor(data);
                ((CursorAdapter) getListAdapter()).changeCursor(data);
                if (isResumed()) {
                    setListShown(true);
                } else {
                    setListShownNoAnimation(true);
                }
                break;
        }
    }
项目:android-money-manager-ex    文件:AllDataListFragment.java   
@Override
public void onLoaderReset(Loader<Cursor> loader) {
    LoaderManager.LoaderCallbacks<Cursor> parent = getSearchResultFragmentLoaderCallbacks();
    if (parent != null) parent.onLoaderReset(loader);

    //((CursorAdapter) getListAdapter()).swapCursor(null);
    ((CursorAdapter) getListAdapter()).changeCursor(null);
}
项目:ViewBinder    文件:BaseLoadActivity.java   
public void initLoad(ListView listView, CursorAdapter adapter, Uri uri,
        String selection, String orderBy) {
    mAdapter = adapter;
    mSelection = selection;
    mOrderBy = orderBy;
    mUri = uri;
    if (listView != null) {
        listView.setAdapter(mAdapter);
        listView.setOnItemClickListener(this);
    }
    getSupportLoaderManager().initLoader(0, null, this);
    loadData(1);
}
项目:Securecom-Text    文件:PushContactSelectionListFragment.java   
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
  ((CursorAdapter) listView.getAdapter()).changeCursor(data);
  emptyText.setText(R.string.contact_selection_group_activity__no_contacts);
  if (data != null && data.getCount() < 40) listView.setFastScrollAlwaysVisible(false);
  else                                      listView.setFastScrollAlwaysVisible(true);
}
项目:saveData    文件:loaderDemoFrag.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    View view = inflater.inflate(R.layout.scorefrag, container, false);
    lv = (ListView) view.findViewById(R.id.listView1);
    //setup the adatper with a null cursor.
    String[] columns = new String[] { MainActivity.KEY_NAME, MainActivity.KEY_SCORE};
    // the XML defined views which the data will be bound to
    int[] to = new int[] { R.id.name, R.id.score };

    //initialize the loader
    getLoaderManager().initLoader(TUTORIAL_LIST_LOADER, null, this);
    // create the adapter using the cursor pointing to the desired data
    //as well as the layout information
    dataAdapter = new SimpleCursorAdapter(
            getActivity().getApplicationContext(), R.layout.scorelist,
            null,   //null now, set in the Loader "Later"
            columns, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    //set the adapter to the listview
    lv.setAdapter(dataAdapter);

    //This button is used to add more data, so the loader will then reload "on it's own".
    btn = (Button)view.findViewById(R.id.btn_add);
       btn.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
            ContentValues initialValues = new ContentValues();
            initialValues.put(MainActivity.KEY_NAME, "Fred");
            initialValues.put(MainActivity.KEY_SCORE, "123");
            Uri uri = getActivity().getContentResolver().insert(CONTENT_URI, initialValues);
        }
       });
    return view;
}
项目:saveData    文件:loaderDemoFrag.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    View view = inflater.inflate(R.layout.scorefrag, container, false);
    lv = (ListView) view.findViewById(R.id.listView1);
    //setup the adatper with a null cursor.
    String[] columns = new String[]{MainActivity.KEY_NAME, MainActivity.KEY_SCORE};
    // the XML defined views which the data will be bound to
    int[] to = new int[]{R.id.name, R.id.score};

    //initialize the loader
    getLoaderManager().initLoader(TUTORIAL_LIST_LOADER, null, this);
    // create the adapter using the cursor pointing to the desired data
    //as well as the layout information
    dataAdapter = new SimpleCursorAdapter(
            getActivity().getApplicationContext(), R.layout.scorelist,
            null,   //null now, set in the Loader "Later"
            columns, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    //set the adapter to the listview
    lv.setAdapter(dataAdapter);

    //This button is used to add more data, so the loader will then reload "on it's own".
    btn = (Button) view.findViewById(R.id.btn_add);
    btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ContentValues initialValues = new ContentValues();
            initialValues.put(MainActivity.KEY_NAME, "Fred");
            initialValues.put(MainActivity.KEY_SCORE, "123");
            Uri uri = getActivity().getContentResolver().insert(CONTENT_URI, initialValues);
        }
    });
    return view;
}
项目:Database_Sqlite_Assets_Helper    文件:KeepFragment.java   
public void populateList() {

    String[] from = new String[] { DBAdapter.KEEP_TABLE.COL_DATA, DBAdapter.KEEP_TABLE.COL_COLOR };
    int[] to = new int[] { R.id.textView1, R.id.item_color};

    getLoaderManager().initLoader(1, null, this);
    adapter = new SimpleCursorAdapter(getActivity(), R.layout.keep_item, null, from, to, 
                    CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    adapter.setViewBinder(new Binder());
    setListAdapter(adapter);
    adapter.notifyDataSetChanged();


}
项目:android-recipes-app    文件:RecipeItemListActivity.java   
@Override
public boolean onSuggestionClick(int position) {
    CursorAdapter selectedView = searchView.getSuggestionsAdapter();
    Cursor cursor = (Cursor) selectedView.getItem(position);
    int index = cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1);
    searchView.setQuery(cursor.getString(index), true);
    return true;
}
项目:codetalk    文件:BookmarksListFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // start loading content
    getLoaderManager().initLoader(BOOKMARKS_LIST_LOADER, null, this);
    String[] bindFrom = { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
    int[] bindTo = { R.id.imported_bookmark_title, R.id.imported_bookmark_url };
    mCursorAdapter = new SimpleCursorAdapter(getActivity(), R.layout.import_bookmarks_row, null, bindFrom, bindTo,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    setListAdapter(mCursorAdapter);
}