First of all thank you for taking the time to look ate my question.
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.
Spinner:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> 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);
String Array:
<string name="mnth_picker">Select a Month</string>
<string-array name="mnth_array">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>June</item>
<item>July</item>
<item>August</item>
<item>September</item>
<item>October</item>
<item>November</item>
<item>December</item>
</string-array>
DataBase:
@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);"
);
}
method to get date:
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;
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.
Date format:
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()));
}