本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
};
}
示例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);
};
}
示例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;
}
示例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);
}
示例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);
};
}
示例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();
}
}
示例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();
}