2014-02-18 99 views
0

我想填充一個微調器下拉列表來調用後臺線程顯示列表。我的代碼不起作用。如何從數據庫Android中填充微調器?

ArrayAdapter <CharSequence> adapter = new ArrayAdapter <CharSequence> (this, android.R.layout.simple_spinner_item); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    adapter.add(nameOfMethod(), items); 
    itemspin = (Spinner) findViewById(R.id.itemSpin); 
    itemspin.setAdapter(adapter); 

有人能告訴我我做錯了什麼嗎?

+0

定義不工作。它在做什麼,你期望什麼? –

+0

它在這部分顯示錯誤adapter.add(nameOfMethod(),items); – jajaja

+0

我不確定是否應該使用adapter.add – jajaja

回答

0
 spinner = (Spinner) findViewById(R.id.spinner); 

// database handler 
      DatabaseHandler db = new DatabaseHandler(getApplicationContext()); 

      // Spinner Drop down elements 
      List<String> lables = db.getAllLabels(); 

      // Creating adapter for spinner 
      ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, 
        android.R.layout.simple_spinner_item, lables); 

      // Drop down layout style - list view with radio button 
      dataAdapter 
        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

      // attaching data adapter to spinner 
      spinner.setAdapter(dataAdapter); 
0

試試這個

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items); 
itemspin.setAdapter(adapter); 
相關問題