本文整理匯總了Java中android.support.v4.widget.CursorAdapter類的典型用法代碼示例。如果您正苦於以下問題:Java CursorAdapter類的具體用法?Java CursorAdapter怎麽用?Java CursorAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CursorAdapter類屬於android.support.v4.widget包,在下文中一共展示了CursorAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
@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);
}
示例2: deleteAll
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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();
}
示例3: bindAdapterView
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
@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);
}
}
示例4: setSelectionById
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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;
}
示例5: setSelectionByValue
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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;
}
示例6: populateList
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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();
}
示例7: onCreate
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
@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();
}
示例8: setSearchSuggestionAdapter
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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;
}
示例9: MediaStoreAdapter
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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();
}
示例10: type
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
public static SubjectFactory<CursorAdapterSubject, CursorAdapter> type() {
return new SubjectFactory<CursorAdapterSubject, CursorAdapter>() {
@Override
public CursorAdapterSubject getSubject(FailureStrategy fs, CursorAdapter that) {
return new CursorAdapterSubject(fs, that);
}
};
}
示例11: onLoadFinished
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
@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);
}
示例12: CalendarCursorAdapter
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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);
}
示例13: prepareSearchSuggestions
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
@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;
}
}
示例14: deleteSelectedItems
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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)));
}
}
}
示例15: updateList
import android.support.v4.widget.CursorAdapter; //導入依賴的package包/類
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));
}