2011-11-09 152 views
0

複選框的選中的值我現在面臨的問題是,我無法保存我的複選框無法存儲在ArrayList中

這裏的檢查值是我的代碼:

final Button markpresent = (Button) findViewById(R.id.Button01); 
     markpresent.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) 
      { 
       // Perform action on click 
      Toast.makeText(display.this,"You have selected to mark the present students",Toast.LENGTH_SHORT).show(); 

      SparseBooleanArray checked = lView.getCheckedItemPositions(); 

       ArrayList<String> items = new ArrayList<String>(); 
       for (int i = 0; i < arr2.length; i++) 
       { 
        if (checked.get(i)) 
        { 
         items.add(arr2[i]); 
         System.out.println(items); 
        } 
       } 

       Log.d("", "items:"); 
       for (String string : items) 
       { 
        Log.d("", string); 
        System.out.println(items); 
       } 


      } 
     });  

只有當按鈕被按下時,我希望用戶檢查的值被存儲在一個字符串中。但是,我的代碼工作不正常。

這裏是logcat的:

11-09 15:52:09.678: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{44ffd9d0 com.example/.display} 
11-09 15:52:14.856: DEBUG/KeyguardViewMediator(58): pokeWakelock(5000) 
11-09 15:52:15.187: DEBUG/KeyguardViewMediator(58): pokeWakelock(5000) 
11-09 15:52:15.366: INFO/ActivityManager(58): Displayed activity com.example/.display: 16621 ms (total 16621 ms) 
11-09 15:52:15.746: INFO/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x33ab00:0x33ac0c] in 1153961 ns 
11-09 15:52:15.916: INFO/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x33ac10:0x33add8] in 921629 ns 
11-09 15:52:21.776: DEBUG/(276): items: 
11-09 15:52:28.086: WARN/KeyCharacterMap(276): No keyboard for id 0 
11-09 15:52:28.086: WARN/KeyCharacterMap(276): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 
11-09 15:52:28.296: WARN/InputManagerService(58): Starting input on non-focused client [email protected] (uid=10060 pid=276) 
11-09 15:54:46.557: DEBUG/AndroidRuntime(293): Shutting down VM 
+0

'arr2'的類型是什麼? 'String'數組或'int'數組? –

+0

它是一個字符串數組 –

回答

0

店sharedPreferences的價值,當你再次需要剛從sharedPreferences檢索,做你的任務。

+0

是的,我聽說過SharedPreferences之前。基本上,我需要通過web服務將這些檢查值發送到遠程數據庫,這是我的意圖在存儲數據。我想將它存儲在一個字符串數組中,最好是因爲我已經有了一個將字符串數組插入數據庫的Web服務。但我想知道SharedPreferences文件是否也可以使用我想要的方式作爲我的web服務的參數發送? –