簡體   English   中英

從復選框獲取未經檢查和檢查的值

[英]get unchecked and checked values from a checkbox

我正在嘗試打印復選框列表的內容。 我想按在列表視圖中出現的順序顯示所有未選中的(假值)和選中的(真值)。 到目前為止,我只能獲取真實值,如何獲取未經檢查的錯誤值?

public void selection (){
    final ListView lv = (ListView)findViewById(R.id.treeQuestionsList);
    Intent intent = getIntent();
     int id2 = intent.getIntExtra("id2", 0);
    SparseBooleanArray checked = lv.getCheckedItemPositions();
    int size = checked.size();

    for (int i = 0; i < size; i++) {
        int key = checked.keyAt(i);

    entries.add(new Observation(id2,lv.getCheckedItemPositions().get(key)));

        Log.d(Constants.TAG,"--ID:="+id2+"--checkeddata----"+ entries.get(i).answers);
    }

}

從Android Developers上可用的文檔中,您可能需要結合使用值和密鑰,以獲得所需的結果。

for (int i=0; i < checked.size(); i++) {
    if (checked.valueAt(i)) {
        int key = checked.keyAt(i);
        Log.i(TAG, key + " is selected");
    } else {
        int key = checked.keyAt(i);
        Log.i(TAG, key + " is not selected");
    }
}

您還可以查看getCheckedItemPositions()的功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM