Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FavouritesActivity extends Activity {
- private static final String DB_NAME = "db.sqlite3";
- private static final String TABLE_NAME = "Content";
- private static final String COLUMN_STAR = "star";
- private static final String COLUMN_NAME = "name";
- private SQLiteDatabase database;
- Cursor cursor;
- ListView lvData;
- SimpleCursorAdapter scAdapter;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this,
- DB_NAME);
- database = dbOpenHelper.openDataBase();
- refreshCursor();
- String[] from = new String[] { COLUMN_NAME };
- int[] to = new int[] { R.id.tvText };
- scAdapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor,
- from, to);
- lvData = (ListView) findViewById(R.id.list);
- lvData.setAdapter(scAdapter);
- lvData.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- String entryID = new Integer(position).toString();
- Intent intent = new Intent();
- intent.setClass(FavouritesActivity.this, ViewFavsActivity.class);
- Bundle b = new Bundle();
- b.putString("elementId", entryID);
- intent.putExtras(b);
- startActivity(intent);
- }
- });
- }
- private void refreshCursor() {
- stopManagingCursor(cursor);
- cursor = database.query(TABLE_NAME, null, COLUMN_STAR + " = ?",
- new String[] { "yes" }, null, null, null);
- startManagingCursor(cursor);
- }
- protected void onDestroy() {
- super.onDestroy();
- database.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment