Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Method to get all data from database table:
- public Cursor getAllData() {
- return db.query(DATABASE_TABLE, new String[] {KEY_NAME},
- null, null, null, null, null);
- }
- Here is how I am trying to get and populate data into ListView
- public class MainActivity extends Activity {
- ArrayList<Actors> actorsList;
- ActorAdapter adapter;
- SQLiteDB sqliteDB;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- sqliteDB = new SQLiteDB(MainActivity.this);
- try {
- actorsList = new ArrayList<Actors>();
- new JSONAsyncTask().execute("JSON link");
- Toast.makeText(getBaseContext(), "Data from Webservice", Toast.LENGTH_SHORT).show();
- }
- catch(Exception e) {
- fetchSQLiteData();
- Toast.makeText(getBaseContext(), "Data from SQLite DB", Toast.LENGTH_SHORT).show();
- }
- ListView listview = (ListView)findViewById(R.id.list);
- adapter = new ActorAdapter(getApplicationContext(), R.layout.row, actorsList);
- listview.setAdapter(adapter);
- }
- private void fetchSQLiteData() {
- // TODO Auto-generated method stub
- sqliteDB.open();
- Cursor c = sqliteDB.getAllData();
- // what to do here, to put data into ListView
- sqliteDB.close();
- }
- 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