Guest User

Favourites activity

a guest
Sep 26th, 2012
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. public class FavouritesActivity extends Activity {
  2.  
  3.     private static final String DB_NAME = "db.sqlite3";
  4.     private static final String TABLE_NAME = "Content";
  5.     private static final String COLUMN_STAR = "star";
  6.     private static final String COLUMN_NAME = "name";
  7.     private SQLiteDatabase database;
  8.  
  9.     Cursor cursor;
  10.     ListView lvData;
  11.     SimpleCursorAdapter scAdapter;
  12.  
  13.     @Override
  14.     public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.         ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this,
  18.                 DB_NAME);
  19.         database = dbOpenHelper.openDataBase();
  20.  
  21.         refreshCursor();
  22.  
  23.         String[] from = new String[] { COLUMN_NAME };
  24.         int[] to = new int[] { R.id.tvText };
  25.  
  26.         scAdapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor,
  27.                 from, to);
  28.         lvData = (ListView) findViewById(R.id.list);
  29.         lvData.setAdapter(scAdapter);
  30.  
  31.         lvData.setOnItemClickListener(new OnItemClickListener() {
  32.             public void onItemClick(AdapterView<?> parent, View view,
  33.                     int position, long id) {
  34.                 String entryID = new Integer(position).toString();
  35.  
  36.                 Intent intent = new Intent();
  37.                 intent.setClass(FavouritesActivity.this, ViewFavsActivity.class);
  38.  
  39.                 Bundle b = new Bundle();
  40.                 b.putString("elementId", entryID);
  41.                 intent.putExtras(b);
  42.                 startActivity(intent);
  43.             }
  44.         });
  45.     }
  46.  
  47.     private void refreshCursor() {
  48.         stopManagingCursor(cursor);
  49.  
  50.         cursor = database.query(TABLE_NAME, null, COLUMN_STAR + " = ?",
  51.                 new String[] { "yes" }, null, null, null);
  52.  
  53.         startManagingCursor(cursor);
  54.     }
  55.  
  56.     protected void onDestroy() {
  57.         super.onDestroy();
  58.         database.close();
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment