- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何同时读取 3 个微调器选择的项目?我在 WorkDetails.java
中有 spinner1,2,3
,它们的值已插入到 SQLite
中。在我的 UpdatePage.java
中,我想检索出选定的项目,并且选定的项目应该首先显示在微调器 project1、project2 和 project3
中。
更新页面.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);
}
假设spinner1
值为1,spinner2
值为2,spinner3
值为3。当来到updatePage
时,微调器 project1
应首先显示 1,project2
应显示 2,依此类推。但是现在的问题是project1,2,3先显示值1...我该如何实现呢?
最佳答案
您可以为此尝试一些逻辑
从数据库中获取三个值。让他们成为
selected_value_of_spinner1
,selected_value_of_spinner2
,selected_value_of_spinner3
然后定义你的方法getPosition
如下
public int getPosition(Spinner your_spinner, String string_value){
int position = 0;
for (int i=0;i<your_spinner.getCount();i++){
if (your_spinner.getItemAtPosition(i).equals(string_value)){
position = i;
}
}
return position;
}
在微调器中显示从数据库中获取的值,如下所示
your_spinner1.setSelection(getPosition(your_spinner1, selected_value_of_spinner1));
your_spinner2.setSelection(getPosition(your_spinner2, selected_value_of_spinner2));
your_spinner3.setSelection(getPosition(your_spinner3, selected_value_of_spinner3));
基本上这里发生的是
从数据库中获取值
您通过 getPosition()
方法匹配微调器中从数据库中获取的值以获取其在微调器中的位置。
根据您通过 setSelection(position)
方法从第 2 步获得的位置设置微调器值。
关于java - 同时阅读 3 个所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33250968/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!