How to read 3 spinner selected item in the same time? I have spinner1,2,3
in WorkDetails.java
and their value has been inserted into SQLite
. In my UpdatePage.java
, I want to retrieve the selected item out and the selected item should be displayed first in spinner project1,project2 and project3
.
UpdatePage.java
public void RetrievePage(String name,String date, String id) {
final String name2 = name;
final String date2=date;
final String id2 = id;
final EditText name3 = (EditText) findViewById(R.id.editText9);
final EditText date3 = (EditText) findViewById(R.id.editText12);
name3.setText(name2);
date3.setText(date2);
database = dbHelper.getWritableDatabase();
c = database.rawQuery(
"SELECT i.Weather, i.Status,w.Subcontractors, w.NumberOfPerson,"+
"w.NumberOfHours, wd.Project, wd.WorkDescription, wd.Per,"+
"wd.TimeIn, wd.TimeOut FROM Information i LEFT JOIN WorkForce w "+
"ON w.TInfo_id = i._id "+
"LEFT JOIN WorkDetails wd ON wd.Twf_id=w._id "+
"WHERE i.Name = ? AND i._id= ? ",
new String[]{String.valueOf(name2),String.valueOf(id2)}, null);
if (c != null) {
while (c.moveToNext()) {
Details WD = new Details();
String Project11 = c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
String Project22 =c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
String Project33 =c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
addProject1(Project11);
addProject2(Project22);
addProject3(Project33);
WD.setProject(Project11);
WD.setProject(Project22);
WD.setProject(Project33);
}
}
c.close();
}
public void addProject1(String l) {
project1 = (Spinner) findViewById(R.id.spinner8);
String[] arr = new String[]{"1","2","3"};
List<String> list = new ArrayList<String>();
String project11 = l;
list.add(project11);
for (String s : arr) {
if (!list.contains(s)) {
list.add(s);
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(UpdatePage.this, android.R.layout.simple_spinner_dropdown_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
project1.setAdapter(adapter);
}
public void addProject2(String d) {
project2 = (Spinner)findViewById(R.id.spinner9);
String[] arr = new String[]{"1","2","3"};
List<String> list = new ArrayList<String>();
String project22 = d;
list.add(project22);
for (String s:arr) {
if(!list.contains(s)) {
list.add(s);
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(UpdatePage.this, android.R.layout.simple_spinner_dropdown_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
project2.setAdapter(adapter);
}
public void addProject3(String e) {
project3 = (Spinner)findViewById(R.id.spinner13);
String[] arr = new String[]{"1","2","3"};
List<String> list = new ArrayList<String>();
String project33 = e;
list.add(project33);
for (String s:arr) {
if (!list.contains(s)) {
list.add(s);
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(UpdatePage.this, android.R.layout.simple_spinner_dropdown_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
project3.setAdapter(adapter);
}
Assume spinner1
holds value 1, spinner2
holds 2 and spinner3
holds 3. When come to updatePage
, spinner project1
should display 1 first, project2
display 2 and so on. But the problem now is project1,2,and 3 display value 1 first...how can I achieve this?
String Project11 = c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project)); String Project22 =c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project)); String Project33 =c.getString(c.getColumnIndexOrThrow(MyDatabaseHelper.Project));
. I should addc.moveToNext()
between them – Cordell