【问题标题】:isChecked() won't workisChecked() 不起作用
【发布时间】:2016-06-14 21:52:37
【问题描述】:

我不知道为什么,但是isChecked() 不起作用,它说它无法解析符号。有什么我应该进口的吗?我还想问您如何更改Textview 中的文字谢谢!

package xyz.ashraf.whoisdelasalle;

import android.view.View;
import android.widget.CheckBox;

/**
 * Created by Ashraf on 3/2/2016.
 */
public class check_Button extends Pop_sallian{
CheckBox concern = (CheckBox) findViewById(R.id.concern);
CheckBox faith = (CheckBox) findViewById(R.id.faith);
CheckBox respect = (CheckBox) findViewById(R.id.respect);
CheckBox education = (CheckBox) findViewById(R.id.education);
CheckBox community = (CheckBox) findViewById(R.id.community);

int con = 0;
int fai = 0;
int res = 0;
int edu = 0;
int com = 0;

if (concern.isChecked()) {
    con++;
}
if (faith.isChecked()) {
    fai++;
}
if(respect.isChecked()){
    res++;
}
if(education.isChecked()){
    edu++;
}
if(community.isChecked()){
    com++;
}
}

【问题讨论】:

  • 哦,你做错地方了
  • 覆盖 oncreate 方法并在该方法中执行
  • 您不能在类的主体中编写逻辑代码。你的方法声明在哪里?
  • 你能写一个解释它的答案吗?

标签: android checkbox textview


【解决方案1】:

您必须先创建onCreate 方法...然后在其中添加您的代码

 @Override
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.yourActivity);

     CheckBox concern = (CheckBox) findViewById(R.id.concern);
     CheckBox faith = (CheckBox) findViewById(R.id.faith);
     CheckBox respect = (CheckBox) findViewById(R.id.respect);
     CheckBox education = (CheckBox) findViewById(R.id.education);
     CheckBox community = (CheckBox) findViewById(R.id.community);

     int con = 0;
    int fai = 0;
    int res = 0;
    int edu = 0;
    int com = 0;

    if (concern.isChecked()) {
        con++;
    }
    if (faith.isChecked()) {
        fai++;
    }
    if(respect.isChecked()){
        res++;
    }
    if(education.isChecked()){
        edu++;
    }
    if(community.isChecked()){
        com++;
    }


}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-30
    • 2013-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-06
    • 2012-08-21
    相关资源
    最近更新 更多