Пример #1
0
  @Override
  public void onCreateContextMenu(
      final ContextMenu menu, final View v, final ContextMenu.ContextMenuInfo menuInfo) {
    FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getContext());
    SQLiteDatabase db = mDbHelper.getReadableDatabase();

    // Define a projection that specifies which columns from the database
    // you will actually use after this query.
    String[] projection = {
      FeedReaderContract.FeedEntry.COLUMN_NAME_BOOK,
      FeedReaderContract.FeedEntry.COLUMN_NAME_CH,
      FeedReaderContract.FeedEntry.COLUMN_NAME_START,
      FeedReaderContract.FeedEntry.COLUMN_NAME_END,
    };
    String selection = FeedReaderContract.FeedEntry.COLUMN_NAME_BOOK + " not NULL";
    String[] selectionArgs = null;
    // How you want the results sorted in the resulting Cursor
    String sortOrder = FeedReaderContract.FeedEntry.COLUMN_NAME_BOOK + " DESC";

    Cursor c =
        db.query(
            FeedReaderContract.FeedEntry.TABLE_NAME, // The table to query
            projection, // The columns to return
            selection, // The columns for the WHERE clause
            selectionArgs, // The values for the WHERE clause
            null, // don't group the rows
            null, // don't filter by row groups
            sortOrder // The sort order
            );
    List<String> array = new ArrayList<>();
    while (c.moveToNext()) {
      String verse =
          c.getString(c.getColumnIndexOrThrow(FeedReaderContract.FeedEntry.COLUMN_NAME_BOOK))
              + " "
              + c.getString(c.getColumnIndexOrThrow(FeedReaderContract.FeedEntry.COLUMN_NAME_CH))
              + ":"
              + c.getString(
                  c.getColumnIndexOrThrow(FeedReaderContract.FeedEntry.COLUMN_NAME_START));
      array.add(verse);
    }
    for (int i = 0; i < array.size(); i++) {
      menu.add(Menu.NONE, i, i, array.get(i));
    }
  }
Пример #2
0
  @Override
  public boolean onContextItemSelected(final MenuItem item) {
    AdapterView.AdapterContextMenuInfo info =
        (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    quizVerse = item.getTitle().toString();
    TextView tv2 = (TextView) rootview.findViewById(R.id.textView);
    tv2.setText(quizVerse);
    FeedReaderDbHelper mDbHelper = new FeedReaderDbHelper(getContext());
    SQLiteDatabase db = mDbHelper.getReadableDatabase();

    // Define a projection that specifies which columns from the database
    // you will actually use after this query.
    String[] projection = {
      FeedReaderContract.FeedEntry.COLUMN_NAME_TEXT,
    };
    String selection = FeedReaderContract.FeedEntry.COLUMN_NAME_BOOK + " = '" + "Jeremiah" + "'";
    String[] selectionArgs = null;
    // How you want the results sorted in the resulting Cursor
    String sortOrder = null;

    Cursor c =
        db.query(
            FeedReaderContract.FeedEntry.TABLE_NAME, // The table to query
            projection, // The columns to return
            selection, // The columns for the WHERE clause
            selectionArgs, // The values for the WHERE clause
            null, // don't group the rows
            null, // don't filter by row groups
            sortOrder // The sort order
            );
    c.moveToFirst();
    correctText =
        c.getString(c.getColumnIndexOrThrow(FeedReaderContract.FeedEntry.COLUMN_NAME_TEXT))
            .replaceAll("[[0-9]]", "")
            .substring(4);
    return false;
  }