首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >isChecked()不能工作

isChecked()不能工作
EN

Stack Overflow用户
提问于 2016-03-02 07:03:06
回答 1查看 1.6K关注 0票数 1

我不知道为什么,但是isChecked()不能工作,它说它不能解析符号。我有什么要进口的吗。我也想问一下,你将如何修改Textview中的文本,谢谢!

代码语言:javascript
复制
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++;
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-02 07:18:16

必须首先创建onCreate方法..。然后将代码添加到其中。

代码语言:javascript
复制
 @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++;
    }


}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35740539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档