我遇到的问题是我无法存储复选框的选中值
这是我的代码:
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);
}
}
});
仅当按下按钮时,我希望用户检查的值存储在String中。但是,我的代码工作不正常。
这是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 com.android.internal.view.IInputMethodClient$Stub$Proxy@450bebc0 (uid=10060 pid=276)
11-09 15:54:46.557: DEBUG/AndroidRuntime(293): Shutting down VM
答案 0 :(得分:0)
将值存储在sharedPreferences中,当您需要再次从sharedPreferences中检索并执行任务时。