Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid development with sqlite: How to use string result from a database query without using a listview?
    primarykey
    data
    text
    <p>I've been working on this for days, off and on. What I want to do is when a user clicks on a button, run a query against my sql lite database that returns 1 value (happens to be an integer, but string is fine), which I can then put into a text box. (Also When the user changes input values, and clicks the button, they get a different result. </p> <p>I have gone through a ton of examples, but they all use a listview at the end to display a set of rows. Is there a way to take the results from my database adapter, which I thought was a string . In my code from mydbadapter below, I would like to return a value from KEY_FEE column:</p> <pre><code>public String getdata(){ String[] columns = new String[]{KEY_ROWID, KEY_SPEED, KEY_TIME, KEY_FEE }; Cursor c = myDatabase.query(DATABASE_TABLE, columns, "speed like '25' AND " + "time like '50'", null, null, null, null); String result =""; int iRow =c.getColumnIndex(KEY_ROWID); int iSPEED =c.getColumnIndex(KEY_SPEED); int iTIME=c.getColumnIndex(KEY_TIME); int iFEE =c.getColumnIndex(KEY_FEE); for (c.moveToFirst(); !c.isAfterLast();c.moveToNext()){ result = result + c.getString(iRow) + " " +c.getString(iSPEED) + " " +c.getString(iTIME) + " " +c.getString(iFEE) + "/n"; } return result; } </code></pre> <p>IS this <strong>result</strong> actually a string? </p> <p>If so, how can I access it from my main program, upon button click: Button.OnClickListener buttonOnClickListener = new Button.OnClickListener(){</p> <pre><code> @Override public void onClick(View v) { System.out.println("The calculate FEE button was clicked " ); //TODO //getdata here from database, to a variable for lineout, sub in for "60". // myDbHelper.getdata(); //set the stringVal variable to the Fee _stringVal = "Fee is:" **???how to specify the result string from dbhelper here?**; //sets the text textview based on prior code: _value = (TextView) findViewById(R.id.textView3); _value.setText(_stringVal); //System.out.println("Text should say "+_stringVal); // System.out.println("Get Data Has been called. "); } }; </code></pre>
    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