I apologize in advance, I am from Indonesia, so my English may not be good .. I just translate me through google translate
I'm making a android app associated with sqlite. the problem I have, I want to display data from the database according to the selected listview. application is an application that I made a tour guide.
while running the application, will be performing some of the category of existing attractions. if one of the selected categories, such as category: Nature, it will show a list of names that exist in nature in the form of a database listview.
I managed to get it up here.
after that, if I choose one of the name of nature, such as: Losari, it will show a description of Losari according to the database.
I am confused how to display as I described above .. please help me
this file alam.java for displaying listview whose data retrieved from the database
dbadapter db;
protected Cursor cursor;
protected ListAdapter adapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alam);
final ListView dftAlam = (ListView)findViewById(R.id.lv);
final dbadapter db = new dbadapter(this);
ArrayList<DFT_ALAM> dft_alam = db.getAllAlam();
dftAlam.setAdapter(new MyAdapter(this, dft_alam));
dftAlam.setOnItemClickListener(new OnItemClickListener() {
private String nama;
private String alamat;
private String desk;
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String selectedItem = (String) dftAlam.getItemAtPosition(arg2);
String query = "SELECT nama, alamat, desk FROM wisata WHERE nama = '" + selectedItem + "'";
SQLiteDatabase dbs = db.getReadableDatabase();
Cursor result = dbs.rawQuery(query, null);
result.moveToFirst();
nama = result.getString(result.getColumnIndex("nama"));
alamat = result.getString(result.getColumnIndex("alamat"));
desk = result.getString(result.getColumnIndex("desk"));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, null, null, deskAlam.class);
startActivity(intent);
}
});
}
public void onClick(View v) {
}
}
This file deskAlam.java will display a description of the selected option in listview
dbadapter db;
TextView nama = null;
TextView alamat = null;
TextView desk = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.desk);
TextView nama = (TextView)findViewById(R.id.nm);
TextView alamat = (TextView)findViewById(R.id.alm);
TextView desk = (TextView)findViewById(R.id.desk);
dbadapter db = new dbadapter (this);
db.openDataBase();
Cursor c = (Cursor) db.getAllAlam();
if (c.moveToFirst()){
do{
tampil(c);
}while (c.moveToNext());
}
}
public void tampil(Cursor c) {
// TODO Auto-generated method stub
Toast.makeText(this, c.getString(4) + "\n" +
c.getString(5) + "\n" +
c.getString(6), Toast.LENGTH_LONG).show();
}
}
please fix it if something goes wrong or less of the source code I mentioned above