I’m new to android. What i’m trying to do is to populate a listview from my sqlite database.I know how to do it using arrays. Can somebody help me doing this? I know there is a away to adapt the following code and using it for populating the listview using SQLite but i don’t know how to do it.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_item);
final ListView lt = (ListView)findViewById(R.id.ListView01);
List<String> w= new ArrayList<String>();
ArrayAdapter<String> aa;
w.add("waka");
w.add("weka");
w.add("woka");
aa = new ArrayAdapter<String>(this, R.layout.listW, w);
lt.setAdapter(aa);
lt.setTextFilterEnabled(true);
lt.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
final String aux= (String) lt.getItemAtPosition(position);
Intent myIntent = new Intent(infoList.this, tabList.class);
startActivity(myIntent);
}});
}
Thanks
The best way to poputaling a ListView with data is using Content Providers: http://developer.android.com/guide/topics/providers/content-providers.html
Using content providers will you safe headaches regarding open/close operation for the database.