Note that there are some explanatory texts on larger screens.

plurals
  1. POQuery on List Item Click
    primarykey
    data
    text
    <p>I have manage to display local health center listings from my database to a list view, and also successfully display a toast on the clicked item, my goal now is to display the information(address, contact number) on the clicked item from the list and display it to the next activity. Am i suppose to use the putExtras? and How do i make the rawquery? and also i am selecting 3 fields from my database. would that mean i have to make 3 queries as well and 3 bundles?</p> <p>Here is my code:</p> <pre><code>public class Health extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.health); displayHospitals(); } public void displayHospitals (){ DbHelper tblHL = new DbHelper(this); tblHL.open(); ArrayList&lt;String&gt; result = tblHL.getHData(); result = tblHL.getHData(); setListAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, result)); tblHL.close(); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); String hosp = (String)getListAdapter().getItem(position); Toast.makeText(this, hosp, Toast.LENGTH_SHORT).show(); } } </code></pre> <p>Here is my dbhelper class</p> <pre><code>public class DbHelper { public static final String Row_id = "_id"; private static final String db_DgTable = "tblDrugs"; public static final String Row_Name = "faName"; private static final String Row_Drugs = "GenericName"; public static final String Row_Desc = "faInfo"; private static final String db_Name = "dbDrDroid"; private static final String db_Table = "tblFirstAid"; private static final String db_HTable = "tblHospitals"; private static final String Row_HosName = "HospitalName"; private static final String Row_HosAdd = "Address"; private static final String Row_HosReg = "Region"; private static final String Row_HosCity = "City"; private static final String Row_HosContact = "Contact"; private static final String Row_dName = "dName"; private static final String Row_dTable = "tblDisease"; private static final int db_Version = 1; private dbhelp ourhelper; private static Context ourcontext; private SQLiteDatabase ourDB; private static class dbhelp extends SQLiteOpenHelper{ public dbhelp(Context context) { super(context, db_Name, null, db_Version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL("CREATE TABLE IF NOT EXISTS " + db_Table + " (" + Row_id + " INTEGER PRIMARY KEY AUTOINCREMENT, " + Row_Name + " TEXT NOT NULL, " + Row_Desc + " TEXT NOT NULL)" ); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS" + db_Table); onCreate(db); } } public DbHelper (Context c){ ourcontext= c; } public DbHelper open(){ ourhelper = new dbhelp(ourcontext); ourDB = ourhelper.getWritableDatabase(); return this; } public void close(){ ourhelper.close(); } public ArrayList&lt;String&gt; getFAData() { // TODO Auto-generated method stub ArrayList&lt;String&gt; comments = new ArrayList&lt;String&gt;(); String [] columns = new String[]{Row_Name}; Cursor c = ourDB.query(db_Table, columns, null, null, null, null, null); int iRow = c.getColumnIndex(Row_Name); c.moveToFirst(); while (!c.isAfterLast()) { comments.add(c.getString(iRow)); c.moveToNext(); } c.close(); return comments; } public ArrayList&lt;String&gt; getHData(){ ArrayList&lt;String&gt; res = new ArrayList&lt;String&gt;(); String [] columns = new String []{Row_HosName}; Cursor h = ourDB.query(db_HTable, columns, null, null, null, null, Row_HosName); int HRow = h.getColumnIndex(Row_HosName); h.moveToFirst(); while (!h.isAfterLast()) { res.add(h.getString(HRow)); h.moveToNext(); } h.close(); return res; } public ArrayList&lt;String&gt; getDData(){ ArrayList&lt;String&gt; res = new ArrayList&lt;String&gt;(); String [] columns = new String []{Row_dName}; Cursor d = ourDB.query(Row_dTable, columns, null, null, null, null, null); int HRow = d.getColumnIndex(Row_dName); d.moveToFirst(); while (!d.isAfterLast()) { res.add(d.getString(HRow)); d.moveToNext(); } d.close(); return res; } public ArrayList&lt;String&gt; getDgData(){ ArrayList&lt;String&gt; res = new ArrayList&lt;String&gt;(); String [] columns = new String []{Row_Drugs}; Cursor d = ourDB.query(db_DgTable, columns, null, null, null, null, Row_Drugs); int HRow = d.getColumnIndex(Row_Drugs); d.moveToFirst(); while (!d.isAfterLast()) { res.add(d.getString(HRow)); d.moveToNext(); } d.close(); return res; } </code></pre> <p>}</p> <p>What declarations am i missing to add a rawquery in my onitemclick method? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload