【问题标题】:Checkbox count exceed after closing the app and come back关闭应用程序后复选框计数超出并返回
【发布时间】:2016-05-30 05:39:30
【问题描述】:

字符串数组计数为三个。我正在从 gridview 中检查三个画廊图像。

基于数组计数,检查三个图像。但是在关闭应用程序并返回后总是显示exceed debug。它必须再次检查三个复选框。

MainActivity.java:

String[] strArr = {"One","Two","Three"};
    
int size = strArr.length;

    public void changeSelection(View v, int position) {

        if (data.get(position).isSeleted) {
            data.get(position).isSeleted = false;
            
            Log.e("UnChecked","Unchecked");
            
        } else if(size < strArr.length){
            data.get(position).isSeleted = true;
            
            Log.e("Checked","Checked");
            
        } else {
            Log.e("Exceed", "Exceed");
        }

        ((ViewHolder) v.getTag()).imgQueueMultiSelected.setSelected(data.get(position).isSeleted);
    }

谁能帮我解决这个问题?谢谢。

【问题讨论】:

    标签: java android


    【解决方案1】:

    根据您的代码。您实际上可能有一个错字:

    if (data.get(position).isSelected) {
            data.get(position).isSelected = false;
    
            Log.e("UnChecked","Unchecked");
    
        } else if(size < strArr.length){
            data.get(position).isSelected = true;
    
            Log.e("Checked","Checked");
    
        }
    

    isSeleted 应该是 isSelected

    此外,大小永远不会小于 strArr.length,因为它们都是相同的。这会导致您的 if else 语句总是转到最后的 else 语句。

    未选中您的复选框是因为您没有保存应用程序的状态。也许这个答案会对你有所帮助:How to save the state of an Android CheckBox when the users exits the application?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多