List of usage examples for android.database Cursor isNull
boolean isNull(int columnIndex);
true
if the value in the indicated column is null. From source file:android.database.DatabaseUtils.java
/** * Reads a Long out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The INTEGER field to read * @param values The {@link ContentValues} to put the value into * @param key The key to store the value with in the map *//* w w w . j av a 2 s . co m*/ public static void cursorLongToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { Long value = Long.valueOf(cursor.getLong(colIndex)); values.put(key, value); } else { values.put(key, (Long) null); } }
From source file:com.silentcircle.contacts.list.EmailAddressListAdapter.java
protected void bindEmailAddress(ContactListItemView view, Cursor cursor) { CharSequence label = null;//from w w w . j a va2 s .c o m if (!cursor.isNull(EmailQuery.EMAIL_TYPE)) { final int type = cursor.getInt(EmailQuery.EMAIL_TYPE); final String customLabel = cursor.getString(EmailQuery.EMAIL_LABEL); // TODO cache label = EmailLabel.getTypeLabel(getContext().getResources(), type, customLabel); } view.setLabel(label); view.showData(cursor, EmailQuery.EMAIL_ADDRESS); }
From source file:com.csipsimple.backup.Columns.java
public boolean hasField(Cursor c, String name) { int i = c.getColumnIndex(name); return ((i != -1) && !c.isNull(i)); }
From source file:org.jamienicol.episodes.ShowNotesFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { final int notesColumnIndex = data.getColumnIndexOrThrow(ShowsTable.COLUMN_NOTES); if (data.isNull(notesColumnIndex)) { notesView.setText(""); } else {// w w w. j a va 2s .c o m final String text = data.getString(notesColumnIndex); notesView.setText(text); } } }
From source file:org.jamienicol.episodes.ShowDetailsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { int overviewColumnIndex = data.getColumnIndexOrThrow(ShowsTable.COLUMN_OVERVIEW); if (data.isNull(overviewColumnIndex)) { overviewView.setVisibility(View.GONE); } else {/*from w ww.java 2s . c om*/ overviewView.setText(data.getString(overviewColumnIndex).trim()); overviewView.setVisibility(View.VISIBLE); } int firstAiredColumnIndex = data.getColumnIndexOrThrow(ShowsTable.COLUMN_FIRST_AIRED); if (data.isNull(firstAiredColumnIndex)) { firstAiredView.setVisibility(View.GONE); } else { Date firstAired = new Date(data.getLong(firstAiredColumnIndex) * 1000); DateFormat df = DateFormat.getDateInstance(); String firstAiredText = getString(R.string.first_aired, df.format(firstAired)); firstAiredView.setText(firstAiredText); firstAiredView.setVisibility(View.VISIBLE); } } else { overviewView.setVisibility(View.GONE); firstAiredView.setVisibility(View.GONE); } }
From source file:org.sufficientlysecure.keychain.ui.widget.SignKeySpinner.java
@Override boolean isItemEnabled(Cursor cursor) { if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) { return false; }/* ww w . j a v a 2 s.co m*/ if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) { return false; } if (cursor.isNull(mIndexHasSign)) { return false; } // valid key return true; }
From source file:com.external.activeandroid.DataBaseModel.java
@Override public void loadFromCursor(Class<? extends Model> type, Cursor cursor) { final int columnIndex = cursor.getColumnIndex("jsonString"); if (columnIndex < 0) { super.loadFromCursor(type, cursor); return;//from w w w. j a va 2s . c o m } boolean columnIsNull = cursor.isNull(columnIndex); if (!columnIsNull) { jsonString = cursor.getString(columnIndex); try { JSONObject jsonObject = new JSONObject(jsonString); fromJson(jsonObject); } catch (JSONException e) { e.printStackTrace(); } } }
From source file:fr.eoit.activity.util.StationListViewBinder.java
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); boolean isNull = cursor.isNull(columnIndex); TextView textView;/*from w w w.j a v a 2 s . com*/ ImageView imageView; String[] stationNameArray; double price; long volume; int role, stationId = cursor.getInt(cursor.getColumnIndexOrThrow(Station._ID)); switch (viewId) { case R.id.station_name: stationName = cursor.getString(columnIndex); textView = (TextView) view; stationNameArray = stationName.split(" - "); textView.setText(stationNameArray[stationNameArray.length - 1]); break; case R.id.location_name: String regionName = cursor.getString(columnIndex); textView = (TextView) view; stationNameArray = stationName.split(" - "); StringBuilder sb = new StringBuilder(regionName); if (stationNameArray.length == 2) { sb.append(" > ").append(stationNameArray[0]); } else if (stationNameArray.length == 3) { sb.append(" > ").append(stationNameArray[0]).append(" - ").append(stationNameArray[1]); } textView.setText(sb.toString()); break; case R.id.station_icon: int id = cursor.getInt(columnIndex); imageView = (ImageView) view; IconUtil.initRender(id, imageView); break; case R.id.favorite_station: boolean favorite = cursor.getInt(columnIndex) == 1; CheckBox favoriteCheckBox = (CheckBox) view; favoriteCheckBox.setChecked(favorite); favoriteCheckBox.setOnCheckedChangeListener( new FavoriteStationsOnCheckedChangeListener(stationId, favoriteCheckBox.getContext())); break; case R.id.station_prod_icon: role = cursor.getInt(columnIndex); imageView = (ImageView) view; if (role == EOITConst.Stations.TRADE_ROLE || isNull) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } break; case R.id.station_trade_icon: role = cursor.getInt(columnIndex); imageView = (ImageView) view; if (role == EOITConst.Stations.PRODUCTION_ROLE || isNull) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } break; case R.id.corp_standing: float standing = cursor.getFloat(columnIndex); textView = (TextView) view; textView.setText(nf.format(standing)); if (standing > 0) { textView.setTextColor(view.getResources().getColor(R.color.green)); } else if (standing == 0) { textView.setTextColor(view.getResources().getColor(R.color.grey)); } else if (standing < 0) { textView.setTextColor(view.getResources().getColor(R.color.red)); } break; case R.id.buy_price: case R.id.sell_price: price = cursor.getDouble(columnIndex); textView = (TextView) view; PricesUtils.setPrice(textView, price, true); break; case R.id.buy_volume: case R.id.sell_volume: volume = cursor.getLong(columnIndex); textView = (TextView) view; textView.setText(nfVolume.format(volume)); break; default: throw new IllegalArgumentException("viewId : " + viewId); } return true; }
From source file:org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner.java
@Override boolean isItemEnabled(Cursor cursor) { if (cursor.getInt(KeyAdapter.INDEX_IS_REVOKED) != 0) { return false; }//from www .j a va 2 s .c o m if (cursor.getInt(KeyAdapter.INDEX_IS_EXPIRED) != 0) { return false; } if (cursor.isNull(mIndexHasCertify)) { return false; } // valid key return true; }
From source file:co.nerdart.ourss.activity.EntriesListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = getIntent();/*from www. j av a 2 s. c om*/ long feedId = intent.getLongExtra(FeedColumns._ID, 0); String title = null; if (feedId > 0) { Cursor cursor = getContentResolver().query(FeedColumns.CONTENT_URI(feedId), FEED_PROJECTION, null, null, null); if (cursor.moveToFirst()) { title = cursor.isNull(0) ? cursor.getString(1) : cursor.getString(0); iconBytes = cursor.getBlob(2); } cursor.close(); } if (title != null) { setTitle(title); } if (savedInstanceState == null) { EntriesListFragment fragment = new EntriesListFragment(); Bundle args = new Bundle(); args.putParcelable(EntriesListFragment.ARG_URI, intent.getData()); fragment.setArguments(args); fragment.setHasOptionsMenu(true); getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment, "fragment").commit(); } if (iconBytes != null && iconBytes.length > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(24); Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null) { if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } getActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } } if (MainActivity.mNotificationManager == null) { MainActivity.mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); } }