Advertisement
Guest User

ViewFavsActivity

a guest
Sep 26th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. public class ViewFavsActivity extends Activity {
  2.  
  3.     private static final String DB_NAME = "db.sqlite3";
  4.     private static final String COLUMN_ID = "_id";
  5.     private static final String COLUMN_DESC = "description";
  6.     private static final String COLUMN_STAR = "star";
  7.     private static final String TABLE_NAME = "Content";
  8.     private SQLiteDatabase database;
  9.     Bundle bundle;
  10.     Cursor cursor, setTitle;
  11.  
  12.     @Override
  13.     public void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.activity_view);
  16.  
  17.         ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this,
  18.                 DB_NAME);
  19.         database = dbOpenHelper.openDataBase();
  20.         refreshCursor();
  21.         bundle = getIntent().getExtras();
  22.  
  23.         TextView titleText = (TextView) findViewById(R.id.titleText);
  24.         setTitle = database.query(TABLE_NAME, new String[] { COLUMN_DESC },
  25.                 null, null, null, null, null);
  26.  
  27.         int entryID = Integer.parseInt(bundle.getString("elementId"));
  28.  
  29.         setTitle.moveToPosition(entryID);
  30.         titleText.setText(setTitle.getString(setTitle
  31.                 .getColumnIndex(COLUMN_DESC)));
  32.  
  33.     }
  34.  
  35.     private void refreshCursor() {
  36.         stopManagingCursor(cursor);
  37.         Intent intent = getIntent();
  38.  
  39.         cursor = database.query(TABLE_NAME, new String[] { COLUMN_ID, COLUMN_STAR, COLUMN_DESC },
  40.                 "_id = ? AND star = ?",
  41.                 new String[] { intent.getStringExtra("elementId"), "yes" },
  42.                 null, null, null);
  43.     }
  44.  
  45.     protected void onDestroy() {
  46.         super.onDestroy();
  47.         database.close();
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement