当前位置: 首页>>代码示例>>Java>>正文


Java SimpleCursorAdapter类代码示例

本文整理汇总了Java中android.widget.SimpleCursorAdapter的典型用法代码示例。如果您正苦于以下问题:Java SimpleCursorAdapter类的具体用法?Java SimpleCursorAdapter怎么用?Java SimpleCursorAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleCursorAdapter类属于android.widget包,在下文中一共展示了SimpleCursorAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);

    adapter = new SimpleCursorAdapter(activity, R.layout.address_book_row, null,
            new String[] { AddressBookProvider.KEY_LABEL, AddressBookProvider.KEY_ADDRESS },
            new int[] { R.id.address_book_row_label, R.id.address_book_row_address }, 0);
    adapter.setViewBinder(new ViewBinder() {
        @Override
        public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
            if (!AddressBookProvider.KEY_ADDRESS.equals(cursor.getColumnName(columnIndex)))
                return false;

            ((TextView) view).setText(WalletUtils.formatHash(cursor.getString(columnIndex),
                    Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));

            return true;
        }
    });
    setListAdapter(adapter);

    loaderManager.initLoader(0, null, this);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:26,代码来源:SendingAddressesFragment.java

示例2: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver cr = getContentResolver();
    //consulta na main thread, pode ser custoso, usar AsyncTask ou Loader
    Cursor c = cr.query(ContentProviderContract.CONTENT_ESTADOS_URI, null, null, null, null);
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(
                    this,
                    R.layout.itemlista,
                    c,
                    new String[] {ContentProviderContract.STATE_NAME, ContentProviderContract.STATE_CODE},
                    new int[] {R.id.pNome, R.id.pEmail},
                    0);
    setListAdapter(adapter);
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:17,代码来源:ContentConsumerSQLiteActivity.java

示例3: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_content_consumer);
    ListView lv_pessoas = (ListView) findViewById(R.id.lv_Pessoas);
    ContentResolver cr = getContentResolver();
    //consulta na main thread, pode ser custoso, usar AsyncTask ou Loader
    Cursor c = cr.query(ContentProviderContract.CONTENT_LIST_URI, null, null, null, null);
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(
                    this,
                    R.layout.itemlista,
                    c,
                    new String[] {ContentProviderContract.NOME},
                    new int[] {R.id.pNome},
                    0);
    lv_pessoas.setAdapter(adapter);
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:19,代码来源:ContentConsumerActivity.java

示例4: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String from[] = new String[]{ ContactsContract.Contacts.DISPLAY_NAME };
    int to[] = new int[]{ R.id.contactName };
    adapter = new SimpleCursorAdapter(
            getApplicationContext(),
            R.layout.contact,
            null,
            from,
            to,
            0);
    setListAdapter(adapter);
    getLoaderManager().initLoader(0, null, this);

}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:17,代码来源:LerContatosLoaderActivity.java

示例5: fillData

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
private void fillData() {
    // Get all of the rows from the database and create the item list
    mNotesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(mNotesCursor);

    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{NotesDbAdapter.KEY_TITLE};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.text1};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes = 
        new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
    setListAdapter(notes);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:17,代码来源:Notepadv3.java

示例6: fillData

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
private void fillData() {
    // Get all of the rows from the database and create the item list
    mNotesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(mNotesCursor);
    
    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
    
    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.text1};
    
    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes = 
    	    new SimpleCursorAdapter(this, R.layout.notes_row, mNotesCursor, from, to);
    setListAdapter(notes);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:17,代码来源:Notepadv2.java

示例7: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);

    // If no data was given in the intent (because we were started
    // as a MAIN activity), then use our default content provider.
    Intent intent = getIntent();
    if (intent.getData() == null) {
        intent.setData(NoteColumns.CONTENT_URI);
    }

    // Inform the list we provide context menus for items
    getListView().setOnCreateContextMenuListener(this);
    
    // Perform a managed query. The Activity will handle closing and requerying the cursor
    // when needed.
    Cursor cursor = managedQuery(getIntent().getData(), PROJECTION, null, null,
                                    NoteColumns.DEFAULT_SORT_ORDER);

    // Used to map notes entries from the database to views
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
            new String[] { NoteColumns.TITLE }, new int[] { android.R.id.text1 });
    setListAdapter(adapter);
}
 
开发者ID:firebase,项目名称:firebase-testlab-instr-lib,代码行数:27,代码来源:NotesList.java

示例8: loadSpecificViewsFromLayoutXML

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
protected void loadSpecificViewsFromLayoutXML() {
    tvTrackStats = mRootView.findViewById(R.id.tvTrackStats);
    ListView lvTrackFileList = mRootView.findViewById(R.id.lvTrackFileList);

    //statistics
    String selection = DBAdapter.COL_NAME_GPSTRACKDETAIL__GPSTRACK_ID + "=?";
    String[] selectionArgs = {Long.toString(mRowId)};
    int layout = R.layout.oneline_list_layout;

    //noinspection deprecation
    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(getActivity(), layout, mDbAdapter.query(DBAdapter.TABLE_NAME_GPSTRACKDETAIL,
            DBAdapter.COL_LIST_GPSTRACKDETAIL_TABLE, selection, selectionArgs, DBAdapter.COL_NAME_GPSTRACKDETAIL__FILE),
            new String[]{DBAdapter.COL_NAME_GPSTRACKDETAIL__FILE}, new int[]{R.id.tvOneLineListTextSmall});

    lvTrackFileList.setAdapter(cursorAdapter);
}
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:18,代码来源:GPSTrackEditFragment.java

示例9: createPayeeAdapter

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
public static SimpleCursorAdapter createPayeeAdapter(Context context, DatabaseAdapter db) {
    final MyEntityManager em = db.em();
    return new SimpleCursorAdapter(context, android.R.layout.simple_dropdown_item_1line, null,
            new String[]{"e_title"}, new int[]{android.R.id.text1}){
        @Override
        public CharSequence convertToString(Cursor cursor) {
            return cursor.getString(cursor.getColumnIndex("e_title"));
        }

        @Override
        public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
            if (constraint == null) {
                return em.getAllPayees();
            } else {
                return em.getAllPayeesLike(constraint);
            }
        }
    };
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:20,代码来源:TransactionUtils.java

示例10: queryData

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
/**
 * 关注1
 * 模糊查询数据 & 显示到ListView列表上
 */
private void queryData(String tempName) {

    // 1. 模糊搜索
    Cursor cursor = helper.getReadableDatabase().rawQuery(
            "select id as _id,name from Search where name like '%" + tempName + "%' order by id desc ", null);
    // 2. 创建adapter适配器对象 & 装入模糊搜索的结果
    adapter = new SimpleCursorAdapter(mContext, android.R.layout.simple_list_item_1, cursor, new String[] { "name" },
            new int[] { android.R.id.text1 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    // 3. 设置适配器
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

    System.out.println(cursor.getCount());
    // 当输入框为空 & 数据库中有搜索记录时,显示 "删除搜索记录"按钮
    if (tempName.equals("") && cursor.getCount() != 0){
        tv_clear.setVisibility(VISIBLE);
    }
    else {
        tv_clear.setVisibility(INVISIBLE);
    };

}
 
开发者ID:AndroidBoySC,项目名称:Mybilibili,代码行数:27,代码来源:MySearchView.java

示例11: getSmsListAdapter

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
private SimpleCursorAdapter getSmsListAdapter() {
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(
            this,
            android.R.layout.simple_list_item_2,
            DbHelper.getDbHelper(this).getCursor(),
            new String[] { DbHelper.COLUMN_MESSAGE, DbHelper.COLUMN_RECIPIENT_NAME },
            new int[] { android.R.id.text1, android.R.id.text2 }
    );
    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            TextView textView = (TextView) view;
            if (textView.getId() == android.R.id.text2) {
                textView.setText(getFormattedSmsInfo(cursor));
                return true;
            }
            return false;
        }
    });
    return adapter;
}
 
开发者ID:yeriomin,项目名称:SmsScheduler,代码行数:21,代码来源:SmsListActivity.java

示例12: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    DataManager d = new DataManager(getActivity().getApplicationContext());
    Cursor c = d.getTags();

    // Create a new adapter
    SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(getActivity(),
            android.R.layout.simple_list_item_1, c,
            new String[] { DataManager.TABLE_ROW_TAG },
            new int[] { android.R.id.text1 }, 0);

    // Attach the Cursor to the adapter
    setListAdapter(cursorAdapter);
}
 
开发者ID:PacktPublishing,项目名称:Android-Programming-for-Developers,代码行数:17,代码来源:TagsFragment.java

示例13: queryData

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
/**
 * 关注1
 * 模糊查询数据 & 显示到ListView列表上
 */
private void queryData(String tempName) {

    // 1. 模糊搜索
    Cursor cursor = helper.getReadableDatabase().rawQuery(
            "select id as _id,name from records where name like '%" + tempName + "%' order by id desc ", null);
    // 2. 创建adapter适配器对象 & 装入模糊搜索的结果
    adapter = new SimpleCursorAdapter(context, android.R.layout.simple_list_item_1, cursor, new String[] { "name" },
            new int[] { android.R.id.text1 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    // 3. 设置适配器
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

    System.out.println(cursor.getCount());
    // 当输入框为空 & 数据库中有搜索记录时,显示 "删除搜索记录"按钮
    if (tempName.equals("") && cursor.getCount() != 0){
        tv_clear.setVisibility(VISIBLE);
    }
    else {
        tv_clear.setVisibility(INVISIBLE);
    };

}
 
开发者ID:Carson-Ho,项目名称:Search_Layout,代码行数:27,代码来源:SearchView.java

示例14: accessNotes

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
public void accessNotes(View view) {
    EditText pinTxt = (EditText) findViewById(R.id.aci3notesPinText);
    Button abutton = (Button) findViewById(R.id.aci3naccessbutton);
    SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(this);
    String pin = spref.getString(getString(R.string.pkey), "");
    String userpin = pinTxt.getText().toString();

    // XXX Easter Egg?
    if (userpin.equals(pin)) {
        // Display the private notes
        ListView  lview = (ListView) findViewById(R.id.aci3nlistView);
        Cursor cr = getContentResolver().query(NotesProvider.CONTENT_URI, new String[] {"_id", "title", "note"}, null, null, null);
        String[] columns = {NotesProvider.C_TITLE, NotesProvider.C_NOTE};
        int [] fields = {R.id.title_entry, R.id.note_entry};
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.notes_entry ,cr, columns, fields, 0);
        lview.setAdapter(adapter);
        pinTxt.setVisibility(View.INVISIBLE);
        abutton.setVisibility(View.INVISIBLE);
        //cr.close();

    }
    else {
        Toast.makeText(this, "Please Enter a valid pin!", Toast.LENGTH_SHORT).show();
    }

}
 
开发者ID:payatu,项目名称:diva-android,代码行数:27,代码来源:AccessControl3NotesActivity.java

示例15: onCreate

import android.widget.SimpleCursorAdapter; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "notes-db", null);
    db = helper.getWritableDatabase();
    daoMaster = new DaoMaster(db);
    daoSession = daoMaster.newSession();
    userInfoDao = daoSession.getNoteDao();

    String textColumn = UserInfoDao.Properties.Text.columnName;
    String orderBy = textColumn + " COLLATE LOCALIZED ASC";
    cursor = db.query(userInfoDao.getTablename(), userInfoDao.getAllColumns(), null, null, null, null, orderBy);
    String[] from = { textColumn, UserInfoDao.Properties.Comment.columnName };
    int[] to = { android.R.id.text1, android.R.id.text2 };

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from,
            to);
    setListAdapter(adapter);

    editTextName = (EditText) findViewById(R.id.editTextName);
    editTextAge = (EditText) findViewById(R.id.editTextAge);
    addUiListeners();
}
 
开发者ID:xulailing,项目名称:android-open-project-demo-master,代码行数:27,代码来源:UserInfoActivity.java


注:本文中的android.widget.SimpleCursorAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。