本文整理匯總了Java中android.widget.CursorAdapter類的典型用法代碼示例。如果您正苦於以下問題:Java CursorAdapter類的具體用法?Java CursorAdapter怎麽用?Java CursorAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CursorAdapter類屬於android.widget包,在下文中一共展示了CursorAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: queryData
import android.widget.CursorAdapter; //導入依賴的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);
};
}
示例2: delete
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
final RoadModel road = (RoadModel) model;
if (road.isDefaultRoad()) {
showDefaultProjectToast();
return;
}
new AsyncTask<Void, Void, Cursor>() {
@Override
protected Cursor doInBackground(Void[] params) {
MeasurementsDataHelper.getInstance().deleteRoad(road.getId(), true);
final Cursor cursor = roadDAO.getAllRoadByFolderIdCursor(((RoadModel) model).getFolderId());
return cursor;
}
@Override
protected void onPostExecute(Cursor o) {
super.onPostExecute(o);
((CursorAdapter)getAdapter()).swapCursor(o);
}
}.execute();
}
示例3: delete
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
new AsyncTask<Void, Void, Cursor>() {
@Override
protected Cursor doInBackground(Void[] params) {
MeasurementModel measurement = (MeasurementModel) model;
MeasurementsDataHelper.getInstance().deleteMeasurement(measurement.getId(), true);
final Cursor cursor = measurementDAO.getAllMeasurementByRoadIdCursor(roadModel.getId());
return cursor;
}
@Override
protected void onPostExecute(Cursor o) {
super.onPostExecute(o);
((CursorAdapter)getAdapter()).swapCursor(o);
}
}.execute();
}
示例4: delete
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
final FolderModel project = (FolderModel) model;
if (project.isDefaultProject()) {
showDefaultProjectToast();
return;
}
new AsyncTask<Void, Void, Cursor>() {
@Override
protected Cursor doInBackground(Void[] params) {
MeasurementsDataHelper.getInstance().deleteProject(project.getId(), true);
final Cursor cursor = folderDAO.getAllFolderCursor();
return cursor;
}
@Override
protected void onPostExecute(Cursor o) {
super.onPostExecute(o);
((CursorAdapter)getAdapter()).swapCursor(o);
}
}.execute();
}
示例5: refreshFolders
import android.widget.CursorAdapter; //導入依賴的package包/類
public void refreshFolders() {
new AsyncTask<Void, Void, Cursor>() {
@Override
protected Cursor doInBackground(Void[] params) {
//long folderId = folderDAO.putFolder(folderModel);
MeasurementsDataHelper.getInstance().refreshFoldersCountersSync();
final Cursor cursor = folderDAO.getAllFolderCursor();
return cursor;
}
@Override
protected void onPostExecute(Cursor o) {
super.onPostExecute(o);
((CursorAdapter)getAdapter()).swapCursor(o);
}
}.execute();
}
示例6: delete
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void delete(final BaseModel model) {
new AsyncTask<Void, Void, Cursor>() {
@Override
protected Cursor doInBackground(Void[] params) {
TagModel tagModel = (TagModel) model;
tagDAO.delete(tagModel);
final Cursor cursor = tagDAO.
getTagsByRoadIdCursor(RAApplication.getInstance().getCurrentRoadId());
return cursor;
}
@Override
protected void onPostExecute(Cursor o) {
((CursorAdapter) getAdapter()).swapCursor(o);
}
}.execute();
}
示例7: swapCursor
import android.widget.CursorAdapter; //導入依賴的package包/類
private void swapCursor(){
int offsetFromTop = 0;
int firstVisiblePosition = Math.max(0, feedListView.getFirstVisiblePosition());
if(feedListView.getChildCount() > 0) {
offsetFromTop = feedListView.getChildAt(0).getTop();
}
CursorAdapter newAdapter = ((CursorAdapter) feedListView.getAdapter());
newAdapter.swapCursor(getCursor());
if(SearchHelper.searchToSQL(query) == null) {
((FeedAdapter) newAdapter).setHighlight(Utils.getKeywords(query));
}
feedListView.setAdapter(newAdapter);
feedListView.setSelectionFromTop(firstVisiblePosition, offsetFromTop);
}
示例8: setListInSelectionMode
import android.widget.CursorAdapter; //導入依賴的package包/類
private void setListInSelectionMode(){
inSelectionMode = true;
((FeedAdapter) feedListView.getAdapter()).setSelectionMode(true);
swapCursor();
feedListView.setOnItemLongClickListener(null);
feedListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor c = ((CursorAdapter) feedListView.getAdapter()).getCursor();
c.moveToPosition(position);
boolean isChecked = c.getInt(c.getColumnIndex(MessageStore.COL_CHECKED)) == MessageStore.TRUE;
String message = c.getString(c.getColumnIndex(MessageStore.COL_MESSAGE));
MessageStore.getInstance(getActivity()).checkMessage(message, !isChecked);
swapCursor();
setActionbar();
}
});
setActionbar();
newPostButton.setVisibility(View.INVISIBLE);
}
示例9: swapCursor
import android.widget.CursorAdapter; //導入依賴的package包/類
private void swapCursor(){
int offsetFromTop = 0;
int firstVisiblePosition = Math.max(0, contactListView.getFirstVisiblePosition());
if(contactListView.getChildCount() > 0) {
offsetFromTop = contactListView.getChildAt(0).getTop();
}
CursorAdapter newAdapter = ((CursorAdapter) contactListView.getAdapter());
newAdapter.swapCursor(getCursor());
if(SearchHelper.searchToSQL(query) == null) {
((ContactAdapter) newAdapter).setHighlight(Utils.getKeywords(query));
}
contactListView.setAdapter(newAdapter);
contactListView.setSelectionFromTop(firstVisiblePosition, offsetFromTop);
}
示例10: swapCursor
import android.widget.CursorAdapter; //導入依賴的package包/類
private void swapCursor(){
int offsetFromTop = 0;
int firstVisiblePosition = Math.max(0, listView.getFirstVisiblePosition());
if(listView.getChildCount() > 0) {
offsetFromTop = listView.getChildAt(0).getTop();
}
CursorAdapter newAdapter = ((CursorAdapter) listView.getAdapter());
newAdapter.swapCursor(getCursor());
if(SearchHelper.searchToSQL(query) == null) {
((FeedReplyAdapter) newAdapter).setHighlight(Utils.getKeywords(query));
}
listView.setAdapter(newAdapter);
listView.setSelectionFromTop(firstVisiblePosition, offsetFromTop);
parentMessage.setAdapter(new FeedAdapter(getActivity(), MessageStore.getInstance(getActivity()).getMessageById(messageId), false, feedAdapterCallbacks));
}
示例11: queryData
import android.widget.CursorAdapter; //導入依賴的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);
};
}
示例12: handleSelectAll
import android.widget.CursorAdapter; //導入依賴的package包/類
private void handleSelectAll() {
selectedContacts.clear();
Cursor cursor = null;
try {
cursor = ContactAccessor.getInstance().getCursorForContactsWithNumbers(getActivity());
while (cursor != null && cursor.moveToNext()) {
ContactData contactData = ContactAccessor.getInstance().getContactData(getActivity(), cursor);
if (contactData.numbers.isEmpty()) continue;
else if (contactData.numbers.size() == 1) addSingleNumberContact(contactData);
else addMultipleNumberContact(contactData, null);
}
} finally {
if (cursor != null)
cursor.close();
}
((CursorAdapter)getListView().getAdapter()).notifyDataSetChanged();
}
示例13: onCreate
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversation);
Bundle extras = getIntent().getExtras();
mShowSentMessages = extras.getBoolean("sentMessages", false);
if(mShowSentMessages) {
getActionBar().setTitle(R.string.sent_messages);
} else {
mUserId = extras.getString("fromUserId");
String userEmail = extras.getString("fromUserEmail");
getActionBar().setTitle(userEmail);
}
final ListAdapter adapter = new ConversationAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
getListView().setAdapter(adapter);
getLoaderManager().initLoader(0, null, this);
}
示例14: onCreate
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView listDrinks = getListView();
try {
SQLiteOpenHelper starbuzzDatabaseHelper = new StarbuzzDatabaseHelper(this);
db = starbuzzDatabaseHelper.getReadableDatabase();
cursor = db.query("DRINK",
new String[]{"_id", "NAME"},
null, null, null, null, null);
CursorAdapter listAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
cursor,
new String[]{"NAME"},
new int[]{android.R.id.text1},
0);
listDrinks.setAdapter(listAdapter);
} catch(SQLiteException e) {
Toast toast = Toast.makeText(this, "Database unavailable", Toast.LENGTH_SHORT);
toast.show();
}
}
示例15: onRestart
import android.widget.CursorAdapter; //導入依賴的package包/類
@Override
public void onRestart() {
super.onRestart();
try {
StarbuzzDatabaseHelper starbuzzDatabaseHelper = new StarbuzzDatabaseHelper(this);
db = starbuzzDatabaseHelper.getReadableDatabase();
Cursor newCursor = db.query("DRINK",
new String[] { "_id", "NAME"},
"FAVORITE = 1",
null, null, null, null);
ListView listFavorites = (ListView)findViewById(R.id.list_favorites);
CursorAdapter adapter = (CursorAdapter) listFavorites.getAdapter();
adapter.changeCursor(newCursor);
favoritesCursor = newCursor;
} catch(SQLiteException e) {
Toast toast = Toast.makeText(this, "Database unavailable", Toast.LENGTH_SHORT);
toast.show();
}
}