从数据库中获取数据并将其放在微调器中

时间:2013-07-09 00:55:06

标签: android spinner

我试图从我的数据库获取微调器的数据台,但它没有显示出来;这是我在spinner中设置项目的代码;

protected void onPostExecute(String file_url) {
    // dismiss the progress dialog after getting all desk
    pDialog.dismiss();
    // updating UI from Background Thread
    runOnUiThread(new Runnable() {
        public void run() {
            // Get desk
            for (int i = 0; i < nodes.getLength(); i++) {
                HashMap<String, String> map = new HashMap<String, String>);
                Element e = (Element) nodes.item(i);

                map.put("desk", parser.getValue(e, "desk"));
                mylist.add(map);
            }
            // Adding myList to ListView
            ArrayAdapter adapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,new String[] { "desk" });
            s.setAdapter(adapter);
        }
    });

当我尝试运行它时,它只显示desk而不是db中的数据,我的代码是否有问题?

1 个答案:

答案 0 :(得分:1)

ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_item ,mylist);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);                 
s.setAdapter(adapter);