List of usage examples for android.support.v4.widget ResourceCursorAdapter ResourceCursorAdapter
public ResourceCursorAdapter(Context context, int layout, Cursor c, int flags)
From source file:de.schildbach.wallet.ui.ExchangeRatesFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.exchange_rates_fragment_empty_text)); adapter = new ResourceCursorAdapter(activity, R.layout.exchange_rate_row, null, true) { @Override/* w w w .jav a2 s.c o m*/ public void bindView(final View view, final Context context, final Cursor cursor) { final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor); final boolean isDefaultCurrency = exchangeRate.currencyCode.equals(defaultCurrency); view.setBackgroundResource(isDefaultCurrency ? R.color.bg_less_bright : R.color.bg_bright); final View defaultView = view.findViewById(R.id.exchange_rate_row_default); defaultView.setVisibility(isDefaultCurrency ? View.VISIBLE : View.INVISIBLE); final TextView currencyCodeView = (TextView) view .findViewById(R.id.exchange_rate_row_currency_code); currencyCodeView.setText(exchangeRate.currencyCode); final CurrencyTextView rateView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_rate); rateView.setPrecision(Constants.LOCAL_PRECISION); rateView.setAmount(WalletUtils.localValue(Utils.COIN, exchangeRate.rate)); final CurrencyTextView walletView = (CurrencyTextView) view .findViewById(R.id.exchange_rate_row_balance); walletView.setPrecision(Constants.LOCAL_PRECISION); if (!replaying) { walletView.setAmount(WalletUtils.localValue(balance, exchangeRate.rate)); walletView.setStrikeThru(Constants.TEST); } else { walletView.setText("n/a"); walletView.setStrikeThru(false); } walletView.setTextColor(getResources().getColor(R.color.fg_less_significant)); } }; setListAdapter(adapter); }
From source file:de.schildbach.litecoinwallet.ui.ExchangeRatesFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.exchange_rates_fragment_empty_text)); adapter = new ResourceCursorAdapter(activity, R.layout.exchange_rate_row, null, true) { @Override/* w ww . j a v a2s . c om*/ public void bindView(final View view, final Context context, final Cursor cursor) { final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor); final boolean isDefaultCurrency = exchangeRate.currencyCode.equals(defaultCurrency); view.setBackgroundResource(isDefaultCurrency ? R.color.bg_list_selected : R.color.bg_list); final View defaultView = view.findViewById(R.id.exchange_rate_row_default); defaultView.setVisibility(isDefaultCurrency ? View.VISIBLE : View.INVISIBLE); final TextView currencyCodeView = (TextView) view .findViewById(R.id.exchange_rate_row_currency_code); currencyCodeView.setText(exchangeRate.currencyCode); final CurrencyTextView rateView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_rate); rateView.setPrecision(Constants.LOCAL_PRECISION, 0); rateView.setAmount(WalletUtils.localValue(Utils.COIN, exchangeRate.rate)); final CurrencyTextView walletView = (CurrencyTextView) view .findViewById(R.id.exchange_rate_row_balance); walletView.setPrecision(Constants.LOCAL_PRECISION, 0); if (!replaying) { walletView.setAmount(WalletUtils.localValue(balance, exchangeRate.rate)); walletView.setStrikeThru(Constants.TEST); } else { walletView.setText("n/a"); walletView.setStrikeThru(false); } walletView.setTextColor(getResources().getColor(R.color.fg_less_significant)); } }; setListAdapter(adapter); }
From source file:com.feathercoin.wallet.feathercoin.ui.ExchangeRatesFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.exchange_rates_fragment_empty_text)); adapter = new ResourceCursorAdapter(activity, R.layout.exchange_rate_row, null, true) { @Override/*w w w. ja va 2 s . co m*/ public void bindView(final View view, final Context context, final Cursor cursor) { final ExchangeRatesProvider.ExchangeRate exchangeRate = ExchangeRatesProvider .getExchangeRate(cursor); final boolean isDefaultCurrency = exchangeRate.currencyCode.equals(defaultCurrency); view.setBackgroundResource(isDefaultCurrency ? R.color.bg_less_bright : R.color.bg_bright); final View defaultView = view.findViewById(R.id.exchange_rate_row_default); defaultView.setVisibility(isDefaultCurrency ? View.VISIBLE : View.INVISIBLE); final TextView currencyCodeView = (TextView) view .findViewById(R.id.exchange_rate_row_currency_code); currencyCodeView.setText(exchangeRate.currencyCode); final CurrencyTextView rateView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_rate); rateView.setPrecision(Constants.LOCAL_PRECISION); rateView.setAmount(WalletUtils.localValue(Utils.COIN, exchangeRate.rate)); final CurrencyTextView walletView = (CurrencyTextView) view .findViewById(R.id.exchange_rate_row_balance); walletView.setPrecision(Constants.LOCAL_PRECISION); walletView.setAmount(WalletUtils.localValue(balance, exchangeRate.rate)); walletView.setStrikeThru(Constants.TEST); walletView.setTextColor(getResources().getColor(R.color.fg_less_significant)); } }; setListAdapter(adapter); loaderManager.initLoader(0, null, this); }
From source file:de.schildbach.wallet.digitalcoin.ui.ExchangeRatesFragment.java
@Override public void onActivityCreated(final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setEmptyText(getString(R.string.exchange_rates_fragment_empty_text)); adapter = new ResourceCursorAdapter(activity, R.layout.exchange_rate_row, null, true) { @Override/*from www. j av a 2s . c o m*/ public void bindView(final View view, final Context context, final Cursor cursor) { final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor); final boolean isDefaultCurrency = exchangeRate.currencyCode.equals(defaultCurrency); view.setBackgroundResource(isDefaultCurrency ? R.color.bg_less_bright : R.color.bg_bright); final View defaultView = view.findViewById(R.id.exchange_rate_row_default); defaultView.setVisibility(isDefaultCurrency ? View.VISIBLE : View.INVISIBLE); final TextView currencyCodeView = (TextView) view .findViewById(R.id.exchange_rate_row_currency_code); currencyCodeView.setText(exchangeRate.currencyCode); final CurrencyTextView rateView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_rate); rateView.setPrecision(Constants.LOCAL_PRECISION); rateView.setAmount(WalletUtils.localValue(Utils.COIN, exchangeRate.rate)); final CurrencyTextView walletView = (CurrencyTextView) view .findViewById(R.id.exchange_rate_row_balance); walletView.setPrecision(Constants.LOCAL_PRECISION); walletView.setAmount(WalletUtils.localValue(balance, exchangeRate.rate)); walletView.setStrikeThru(Constants.TEST); walletView.setTextColor(getResources().getColor(R.color.fg_less_significant)); } }; setListAdapter(adapter); loaderManager.initLoader(0, null, this); }
From source file:com.nogago.android.tracks.MarkerListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); if (trackId == -1L) { Log.d(TAG, "invalid track id"); finish();//from www. jav a 2 s . c o m return; } setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setContentView(R.layout.marker_list); getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); ListView listView = (ListView) findViewById(R.id.marker_list); listView.setEmptyView(findViewById(R.id.marker_list_empty)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE); int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS; String name = cursor.getString(nameIndex); int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin; String contentDescription = getString(R.string.icon_marker); String category = statistics ? null : cursor.getString(categoryIndex); long time = cursor.getLong(timeIndex); String description = statistics ? null : cursor.getString(descriptionIndex); ListItemUtils.setListItem(MarkerListActivity.this, view, name, iconId, contentDescription, category, null, null, time, description); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); final long firstWaypointId = MyTracksProviderUtils.Factory.get(this).getFirstWaypointId(trackId); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION, WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?", new String[] { String.valueOf(trackId), String.valueOf(firstWaypointId) }, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); }
From source file:org.cowboycoders.cyclisimo.MarkerListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); if (trackId == -1L) { Log.d(TAG, "invalid track id"); finish();/* w w w . j av a 2 s .com*/ return; } setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); ListView listView = (ListView) findViewById(R.id.marker_list); listView.setEmptyView(findViewById(R.id.marker_list_empty)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE); int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME); int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS; int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin; String category = statistics ? null : cursor.getString(categoryIndex); String description = statistics ? null : cursor.getString(descriptionIndex); long time = cursor.getLong(timeIndex); String startTime = time == 0L ? null : StringUtils.formatRelativeDateTime(MarkerListActivity.this, time); ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.icon_marker, cursor.getString(nameIndex), category, null, null, startTime, description); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); final long firstWaypointId = MyTracksProviderUtils.Factory.get(this).getFirstWaypointId(trackId); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION, WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?", new String[] { String.valueOf(trackId), String.valueOf(firstWaypointId) }, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); }
From source file:com.google.android.apps.mytracks.MarkerListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageButton backButton = (ImageButton) findViewById(R.id.listBtnBarBack); if (backButton != null) backButton.setOnClickListener(new OnClickListener() { @Override//ww w. j av a 2s . c o m public void onClick(View v) { MarkerListActivity.this.finish(); } }); // listBtnBarSearch listBtnBarMarker ImageButton sButton = (ImageButton) findViewById(R.id.listBtnBarSearch); if (sButton != null) sButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ApiAdapterFactory.getApiAdapter().handleSearchMenuSelection(MarkerListActivity.this); } }); ImageButton mButton = (ImageButton) findViewById(R.id.listBtnBarMarker); if (mButton != null) mButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerEditActivity.class) .putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId); startActivity(intent); } }); trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); if (trackId == -1L) { Log.d(TAG, "invalid track id"); finish(); return; } setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); ListView listView = (ListView) findViewById(R.id.marker_list); listView.setEmptyView(findViewById(R.id.marker_list_empty)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE); int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME); int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS; int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin; String category = statistics ? null : cursor.getString(categoryIndex); String description = statistics ? null : cursor.getString(descriptionIndex); long time = cursor.getLong(timeIndex); String startTime = time == 0L ? null : StringUtils.formatRelativeDateTime(MarkerListActivity.this, time); ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.icon_marker, cursor.getString(nameIndex), category, null, null, startTime, description); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); final long firstWaypointId = MyTracksProviderUtils.Factory.get(this).getFirstWaypointId(trackId); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION, WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?", new String[] { String.valueOf(trackId), String.valueOf(firstWaypointId) }, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); }
From source file:br.com.bioscada.apps.biotracks.MarkerListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); if (trackId == -1L) { Log.d(TAG, "invalid track id"); finish();// w w w . j av a 2 s.com return; } track = myTracksProviderUtils.getTrack(trackId); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); listView = (ListView) findViewById(R.id.marker_list); listView.setEmptyView(findViewById(R.id.marker_list_empty)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE); int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME); int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL); boolean statistics = Waypoint.WaypointType.values()[cursor .getInt(typeIndex)] == Waypoint.WaypointType.STATISTICS; int iconId = statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin; String name = cursor.getString(nameIndex); long time = cursor.getLong(timeIndex); String category = statistics ? null : cursor.getString(categoryIndex); String description = statistics ? null : cursor.getString(descriptionIndex); String photoUrl = cursor.getString(photoUrlIndex); ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.image_marker, name, null, null, null, 0, time, false, category, description, photoUrl); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); final long firstWaypointId = myTracksProviderUtils.getFirstWaypointId(trackId); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION, WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?", new String[] { String.valueOf(track.getId()), String.valueOf(firstWaypointId) }, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); }
From source file:org.dicadeveloper.runnerapp.MarkerListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L); if (trackId == -1L) { Log.d(TAG, "invalid track id"); finish();//from w w w.j a va 2 s . c o m return; } track = myTracksProviderUtils.getTrack(trackId); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); listView = (ListView) findViewById(R.id.marker_list); listView.setEmptyView(findViewById(R.id.marker_list_empty)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(MarkerListActivity.this, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, id); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE); int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME); int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); int photoUrlIndex = cursor.getColumnIndex(WaypointsColumns.PHOTOURL); boolean statistics = WaypointType.values()[cursor.getInt(typeIndex)] == WaypointType.STATISTICS; int iconId = statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin; String name = cursor.getString(nameIndex); long time = cursor.getLong(timeIndex); String category = statistics ? null : cursor.getString(categoryIndex); String description = statistics ? null : cursor.getString(descriptionIndex); String photoUrl = cursor.getString(photoUrlIndex); ListItemUtils.setListItem(MarkerListActivity.this, view, false, true, iconId, R.string.image_marker, name, null, null, null, 0, time, false, category, description, photoUrl); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); final long firstWaypointId = myTracksProviderUtils.getFirstWaypointId(trackId); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION, WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?", new String[] { String.valueOf(track.getId()), String.valueOf(firstWaypointId) }, null); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); }
From source file:com.nogago.android.tracks.TrackListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setContentView(R.layout.track_list); trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback); getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE) .registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); metricUnits = PreferencesUtils.getBoolean(this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT); recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key); // ImageButton recordImageButton = (ImageButton) findViewById(R.id.track_list_record_button); // recordImageButton.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // updateMenuItems(true); // startRecording(); // }//from w w w . java 2 s. c om // }); listView = (ListView) findViewById(R.id.track_list); listView.setEmptyView(findViewById(R.id.track_list_empty)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class) .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id); startActivity(intent); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int idIndex = cursor.getColumnIndex(TracksColumns._ID); int nameIndex = cursor.getColumnIndex(TracksColumns.NAME); int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION); int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY); int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME); int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE); int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME); int iconIndex = cursor.getColumnIndex(TracksColumns.ICON); boolean isRecording = cursor.getLong(idIndex) == recordingTrackId; String name = cursor.getString(nameIndex); int iconId = isRecording ? R.drawable.menu_record_track : TrackIconUtils.getIconDrawable(cursor.getString(iconIndex)); String iconContentDescription = getString( isRecording ? R.string.icon_recording : R.string.icon_track); String category = cursor.getString(categoryIndex); String totalTime = isRecording ? null : StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalDistance = isRecording ? null : StringUtils.formatDistance(TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); long startTime = cursor.getLong(startTimeIndex); String description = cursor.getString(descriptionIndex); ListItemUtils.setListItem(TrackListActivity.this, view, name, iconId, iconContentDescription, category, totalTime, totalDistance, startTime, description); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { return new CursorLoader(TrackListActivity.this, TracksColumns.CONTENT_URI, PROJECTION, null, null, TracksColumns._ID + " DESC"); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { resourceCursorAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<Cursor> loader) { resourceCursorAdapter.swapCursor(null); } }); showStartupDialogs(); }