刷新数据微调 [英] Refresh spinner data

查看:113
本文介绍了刷新数据微调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个微调卫生组织数据的应用程序是通过从数据库中光标填充。伟大的作品,如果有东西在数据库表上启动。不过,如果我添加了一些应用程序后,运行数据库时我总是微调表明,它具有零的选择,即使人在那里开始。

我的code如下。该adapter.getCursor()重新查询();确实没有好。我想微调,以更新其选择,当用户点击它,我发现说你必须使用微调为OnClickListener背后的TextView在计算器上一对夫妇的帖子。但是,对于我什么也没做。最有可能,因为我缺少一个小

  C1 = myDbHelper.readCars();
    startManagingCursor(C1);    //创建一个数组来指定我们要显示的字段
    的String [] =由新的String [] {昵称};
    //创建我们要我们的数据绑定到显示项目的数组
    INT []为= INT新[] {} android.R.id.text1;    适配器=新SimpleCursorAdapter(这一点,android.R.layout.simple_spinner_item,C1,从,到);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinVehicle.setAdapter(适配器);    txtVehiclePrompt.setOnClickListener(新OnClickListener()
    {
        公共无效的onClick(视图v)
        {
            adapter.getCursor()重新查询()。
        }
    });


解决方案

好吧,
我想通了。我需要关闭转接器,停止管理游标,关闭游标和放大器;关闭在 onSuspend()方法分贝助手然后将一切都在onResume方法备份,因为我是用一个单独的活动记录添加到表中。

I have an application with a Spinner whos data is populated by a cursor from the database. Works great if there is something in the database table on startup. However, if I add something to the database after the app is running my spinner always shows that it has zero choices, even if one was there to begin with.

My code is as follows. The adapter.getCursor().requery(); did no good. I would like the Spinner to update its choices when the user clicks on it and I found a couple posts on StackOverflow that say you have to use the TextView behind the Spinner for the OnClickListener. However, for me that did nothing. Mostly likely because I'm missing one minor

    c1 = myDbHelper.readCars();
    startManagingCursor(c1);

    // create an array to specify which fields we want to display
    String[] from = new String[]{"nickname"};
    // create an array of the display item we want to bind our data to
    int[] to = new int[]{android.R.id.text1};

    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c1, from, to); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinVehicle.setAdapter(adapter);

    txtVehiclePrompt.setOnClickListener(new OnClickListener()
    {
        public void onClick(View v)
        {
            adapter.getCursor().requery();
        }
    });

解决方案

Ok, I got it figured out. I needed to close the adapter, stop managing the cursor, close the cursor & close the db helper in the onSuspend() method then set everything back up in the onResume method since I was using a seperate activity to add records to the table.

这篇关于刷新数据微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆