Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. Method to get all data from database table:
  2.  
  3. public Cursor getAllData() {
  4. return db.query(DATABASE_TABLE, new String[] {KEY_NAME},
  5. null, null, null, null, null);
  6. }
  7.  
  8. Here is how I am trying to get and populate data into ListView
  9.  
  10. public class MainActivity extends Activity {
  11.  
  12. ArrayList<Actors> actorsList;
  13. ActorAdapter adapter;
  14. SQLiteDB sqliteDB;
  15.  
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_main);
  20.  
  21. sqliteDB = new SQLiteDB(MainActivity.this);
  22.  
  23. try {
  24.  
  25. actorsList = new ArrayList<Actors>();
  26. new JSONAsyncTask().execute("JSON link");
  27.  
  28. Toast.makeText(getBaseContext(), "Data from Webservice", Toast.LENGTH_SHORT).show();
  29. }
  30. catch(Exception e) {
  31.  
  32. fetchSQLiteData();
  33. Toast.makeText(getBaseContext(), "Data from SQLite DB", Toast.LENGTH_SHORT).show();
  34. }
  35.  
  36.  
  37. ListView listview = (ListView)findViewById(R.id.list);
  38. adapter = new ActorAdapter(getApplicationContext(), R.layout.row, actorsList);
  39.  
  40. listview.setAdapter(adapter);
  41.  
  42. }
  43.  
  44.  
  45. private void fetchSQLiteData() {
  46. // TODO Auto-generated method stub
  47.  
  48. sqliteDB.open();
  49. Cursor c = sqliteDB.getAllData();
  50.  
  51. // what to do here, to put data into ListView
  52.  
  53. sqliteDB.close();
  54. }
  55.  
  56. As you can see `fetchSQLiteData()` method, I am little bit confuse what to write to populate data into List
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement