2013-03-28 56 views
1

我正在開發同時包含多個答案類型和單一的答案type.the的問題和答案都店sqlite的database.i使用簡單的遊標適配器,並得到有關如何使用主意測驗應用來自here!我的問題是,如果我的答案類型發生變化(單個到多個),我怎樣才能從simple_list_item_single_choice切換到simple_list_item_multiple_choice,以及如何保存答案choosen.Please給一些想法about.Here是編碼....如何使用SimpleCursorAdapter與single_choice和multiple_choice

db = new DBAdapter(this); 
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
    android.R.layout.simple_list_item_1, 
    db.getAllTitles(), 
    new String[] { "title" }, 
    new int[] { android.R.id.text1 }); 

ListView listView = (ListView) findViewById(R.id.list); 
listView.setAdapter(adapter); 

回答

2

檢查驗證碼單選擇:

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
    android.R.layout.simple_list_item_single_choice, 
    db.getAllTitles(), 
    new String[] { "title" }, 
    new int[] { android.R.id.text1 }); 

ListView listView = (ListView) findViewById(R.id.list); 
listView.setAdapter(adapter); 
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

多:

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
    simple_list_item_multiple_choice, 
    db.getAllTitles(), 
    new String[] { "title" }, 
    new int[] { android.R.id.text1 }); 

ListView listView = (ListView) findViewById(R.id.list); 
listView.setAdapter(adapter); 
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

取決於您的要求,您必須設置的上述一個:我認爲ÿ OU已位於硝酸鉀該問題需要單ANS &需要多個取決於你也必須創建列表項單擊像

listView.setOnItemClickListener(new OnItemClickListener() { 

      private String my_sel_items; 

      public void onItemClick(AdapterView arg0, View arg1, int arg2, 
        long arg3) { 
       if(ans == multiple){ 
       my_sel_items = new String("Selected Items"); 
       SparseBooleanArray a = lView.getCheckedItemPositions(); 

       for (int i = 0; i < a.size(); i++) { 
        if (a.valueAt(i)) { 
         my_sel_items = my_sel_items + "," 
           + (String) listView.getAdapter().getItem(i); 
        } 
       } 
       Log.v("values", my_sel_items); 
       }else{ 
       // for single it default selected item 
       } 
      } 
     }); 
+0

確定我得到的第一部分,但不是第二部分還有一兩件事我想補充兩在一個列表視圖中的答案類型,我可以添加它,並最後感謝您的霸權 – ravi 2013-03-28 09:31:13

相關問題