Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to query my sqlite database with a variable
    primarykey
    data
    text
    <p>I want to show the month i have chosen in a textview. To do this i have a spinner, and when i select a month in the spinner this should find all the data i have for this specific month. I am not sure of how to filter the query with a variable, or how to pass the variable from my Start.java class to my KilometerSQL.java class.</p> <p>Since I'm not using a intent to go to the Kilometer.java class i don't know how i can pass the variable.</p> <p>Here is my Start.java class</p> <pre><code>@Override public void onItemSelected(AdapterView&lt;?&gt; parent, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub String month = parent.getSelectedItem().toString(); //This is my month variable KilometerSQL spinner = new KilometerSQL(this); spinner.open(); String dataSpinner = KilometerSQL.spinnerData(); spinner.close(); logbog.setText(dataSpinner); } </code></pre> <p>And here is my KilometerSQL.java class</p> <pre><code>public static String spinnerData() { // TODO Auto-generated method stub String [] columns = new String []{ KEY_DAY, KEY_MONTH, KEY_YEAR, KEY_KILOMETER, KEY_LOCATIONS}; Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_MONTH, null, null, null, null); String result = ""; int iDay = c.getColumnIndex(KEY_DAY); int iMonth = c.getColumnIndex(KEY_MONTH); int iYear = c.getColumnIndex(KEY_YEAR); int iKilometer = c.getColumnIndex(KEY_KILOMETER); int iLocations = c.getColumnIndex(KEY_LOCATIONS); for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){ result = result + c.getString(iDay) + "-" + c.getString(iMonth) + "-" + c.getString(iYear) + " " + c.getString(iKilometer) + " " + c.getString(iLocations) + "\n"; } return result; } </code></pre> <p>I haven't had any luck using answers similar to mine from other users.</p> <p>All help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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