嗨我必须开发一个应用程序..我必须在我的mysql数据库中更新我的微调器值..
例如: ....这里我必须第一次运行应用程序始终只显示Q ..我必须更新状态Q到C后我必须运行应用程序意味着自动显示状态C ....我怎么能开发这个。为什么总是显示Q ...我怎么能在这里管理代码。
这里我使用了以下代码。
private void createSpinnerDropDown() {
//get reference to the spinner from the XML layout
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
//Array list of animals to display in the spinner
List<String> list = new ArrayList<String>();
list.add("Q");
list.add("P");
list.add("F");
list.add("I");
list.add("C");
//create an ArrayAdaptar from the String Array
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
//set the view for the Drop down list
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//set the ArrayAdapter to the spinner
spinner.setAdapter(adapter);
adapter.notifyDataSetChanged();
//attach the listener to the spinner
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
我该如何发展这一点。
答案 0 :(得分:0)
if(list.contains(DATABASE.FETCH()))
spinner.setSelection(list.indexOf(DATABASE.FETCH()));
DATABASE.FETCH()是从数据库中获取数据(C)的方法。
答案 1 :(得分:0)
我不知道它究竟是你想要的。我管理这个,而不是保存所选项只得到selectedItemPosition
int selectedIndex = spinner.getSelectedItemPosition();
当你想从数据库设置微调项时,只需获取索引,比如说
int SavedIndex = FetchSavedSpinnerIndex();
现在将您的微调器项设置为
spinner.setSelection(SavedIndex);