Note that there are some explanatory texts on larger screens.

plurals
  1. POGet monthy data from SQL database choosing the month from a spinner
    primarykey
    data
    text
    <p>First of all thank you for taking the time to look ate my question.</p> <p>Here's is my problem, i created a spinner that as a string array that shows months. What i want to do is to get the data for the month select in the spinner.</p> <p>Spinner:</p> <pre><code>Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource( this, R.array.mnth_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); </code></pre> <p>String Array:</p> <pre><code>&lt;string name="mnth_picker"&gt;Select a Month&lt;/string&gt; &lt;string-array name="mnth_array"&gt; &lt;item&gt;January&lt;/item&gt; &lt;item&gt;February&lt;/item&gt; &lt;item&gt;March&lt;/item&gt; &lt;item&gt;April&lt;/item&gt; &lt;item&gt;May&lt;/item&gt; &lt;item&gt;June&lt;/item&gt; &lt;item&gt;July&lt;/item&gt; &lt;item&gt;August&lt;/item&gt; &lt;item&gt;September&lt;/item&gt; &lt;item&gt;October&lt;/item&gt; &lt;item&gt;November&lt;/item&gt; &lt;item&gt;December&lt;/item&gt; &lt;/string-array&gt; </code></pre> <p>DataBase:</p> <pre><code>@Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL("CREATE TABLE " + DATABASE_TABLEONE + " (" + KEY_ROWIDACTONE + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_DATEACTONE + " TEXT NOT NULL, " + KEY_VALUEACTONE + " TEXT NOT NULL, " + KEY_DESCRIPTIONACTONE + " TEXT NOT NULL);" ); } </code></pre> <p>method to get date:</p> <pre><code>public String getDataDate() { // TODO Auto-generated method stub String[] columns = new String[] { KEY_ROWIDACTONE, KEY_DATEACTONE, KEY_VALUEACTONE, KEY_DESCRIPTIONACTONE }; Cursor c = ourDatabase.query(DATABASE_TABLEONE, columns, null, null, null, null, null); String result = ""; int iRow = c.getColumnIndex(KEY_ROWIDACTONE); int iDate = c.getColumnIndex(KEY_DATEACTONE); int iValue = c.getColumnIndex(KEY_VALUEACTONE); int iDescription = c.getColumnIndex(KEY_DESCRIPTIONACTONE); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { result = result + c.getString(iDate) + "\n "; } return result; </code></pre> <p>What i want is to know u can i get the months from the spinner to get the data that i want for the corresponding month.</p> <p>Date format:</p> <pre><code>final DatePickerDialog.OnDateSetListener mydate = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub myCalendar.set(Calendar.YEAR, year); myCalendar.set(Calendar.MONTH, monthOfYear); myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); updateLabel(); } }; date.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new DatePickerDialog(ActoneSQLentry.this, mydate, myCalendar .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); } }); } private void updateLabel() { String myFormat = "dd/MM/yy"; // In which you need put here SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US); date.setText(sdf.format(myCalendar.getTime())); } </code></pre>
    singulars
    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