Android:Spinner没有让人耳目一新 - 怎么样?

时间:2011-05-24 15:40:07

标签: android refresh spinner

我制作了以下Android小部件:

从sqlite表“Location”填充一个微调器“Location”,它在长按时弹出一个EditText对话框,并在关闭弹出对话框时将EditText'valie保存到“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, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, 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();

2 个答案:

答案 0 :(得分:0)

我在SQLLite中不是很好,但我认为,当您将新值插入表格位置时,您可以发送另一个请求从位置中选择,并将其显示在您的Spinner中,或类似的东西

答案 1 :(得分:0)

也许你需要告诉适配器在通过调用

在Spinner上设置它后自动刷新
adapter1.notifyDataSetChanged();