如何解决Android:微调框自动刷新自身-如何?
| 我制作了以下Android小部件: 从sqlite表“ Location \”填充的微调框“ Location”,长按会弹出EditText对话框,并在关闭弹出对话框时将EditText的值保存到“ Location \”表中。 现在,我想让微调框自动刷新我刚刚输入的新信息,并且不知道如何继续-这是我当前的代码 chooseLocation = (Spinner) this.findViewById(R.id.choose_location);
//set long clicks to add an item
chooseLocation.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
//just an EditText dialog
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
final EditText input = new EditText(MyActivity.this);
builder.setView(input);
builder.setMessage(R.string.add_location)
.setCancelable(false)
.setPositiveButton(R.string.ok,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
if (input.getText().toString().equals(\"\") == false) {
//save EditText to database
db.open();
db.insertLocation(input.getText().toString());
db.close();
}
dialog.cancel();
}})
.setNegativeButton(R.string.cancel,int id) {
dialog.cancel();
}})
.show();
return true;
}});
//Binding the database data and the spinner
Cursor locations = db.getLocations();
startManagingCursor(locations);
SimpleCursorAdapter adapter1 = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item,locations,new String[] { \"_name\"},new int[] { android.R.id.text1});
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
chooseLocation.setAdapter(adapter1);
mb.close();
解决方法
我在SQLLite中不太好,但是我认为,当您将新值插入表Location时,您可以发送另一个请求以从location中进行选择,并将其显示在Spinner中,或类似的东西
,在Spinner上设置适配器并调用以下命令后,可能需要告诉适配器刷新自身
adapter1.notifyDataSetChanged();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。