Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 单击“下一步”按钮后,复选框不会被清除_Java_Android_Android Studio_Checkbox - Fatal编程技术网

Java 单击“下一步”按钮后,复选框不会被清除

Java 单击“下一步”按钮后,复选框不会被清除,java,android,android-studio,checkbox,Java,Android,Android Studio,Checkbox,我正在尝试实现一个调查应用程序,在这个应用程序中,我们只需要问几个问题,而这个问题可以有多个答案。因此,我使用了复选框,但我面临的问题是,当我单击“下一步”按钮时,屏幕上会出现下一个问题,但为上一个问题选中的复选框仍会为新问题选中。因此,我希望在单击下一个问题的“下一步”按钮时清除所有的复选框 public class SurveyActivity extends Activity { Button submit,conti,nextbtn; TextView head,survey,optn

我正在尝试实现一个调查应用程序,在这个应用程序中,我们只需要问几个问题,而这个问题可以有多个答案。因此,我使用了
复选框
,但我面临的问题是,当我单击“下一步”按钮时,屏幕上会出现下一个问题,但为上一个问题选中的
复选框
仍会为新问题选中。因此,我希望在单击下一个问题的“下一步”按钮时清除所有的
复选框

public class SurveyActivity extends Activity {

Button submit,conti,nextbtn;
TextView head,survey,optn1,optn2,optn3,optn4;
String que,opt1,opt2,opt3,opt4;
CheckBox checkBox1,checkBox2,checkBox3,checkBox4;
int surveyno=127;
int questionno=1;

public final static String TAG_SUCCESS = "success";

public static final String EXTRA_MESSAGE = "Message";
String msg;
private ProgressDialog pDialog;


JSONParser jsonParser = new JSONParser();


protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_survey);
    submit=(Button)findViewById(R.id.btnsumbit);
    conti=(Button)findViewById(R.id.btncontinue);
    head=(TextView)findViewById(R.id.tvproject);
    nextbtn=(Button)findViewById(R.id.btnsubmtnxt);
    survey=(TextView)findViewById(R.id.tvsurvey);

    optn1=(TextView)findViewById(R.id.tvoptone);
    optn2=(TextView)findViewById(R.id.tvopttwo);
    optn3=(TextView)findViewById(R.id.tvoptthree);
    optn4=(TextView)findViewById(R.id.tvoptfour);

    checkBox1=(CheckBox)findViewById(R.id.chkopt1);
    checkBox2=(CheckBox)findViewById(R.id.chkopt2);
    checkBox3=(CheckBox)findViewById(R.id.chkopt3);
    checkBox4=(CheckBox)findViewById(R.id.chkopt4);


    nextbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v)
        {

       do
       {
           new FetchQuestion().execute();
           questionno++;
       }while(questionno>=22);
        }
    });


    //font
    Typeface type01=Typeface.createFromAsset(getAssets(),"HelveticaNeue-UltraLight.ttf");
    head.setTypeface(type01);

    submit.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {

            Intent fours1 = new Intent(SurveyActivity.this, BeginAction.class);

            startActivity(fours1);
        }

    });

    conti.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {

            Intent fours1 = new Intent(SurveyActivity.this, EntrpNxtStart.class);

            startActivity(fours1);
        }

    });

   new FetchQuestion().execute();

}


public void linkdn(View view)
{
    Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.linkedin.com"));
    startActivity(intent);
}
public void facebook(View view)
{
    Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com"));
    startActivity(intent);
}
public void twiiter(View view)
{
    Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"));
    startActivity(intent);
}
public void insta(View view)
{
    Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.instagram.com/"));
    startActivity(intent);
}



class FetchQuestion extends AsyncTask<String, String, String>
{
    private ProgressDialog progressDialog;


    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        progressDialog = new ProgressDialog(SurveyActivity.this);
        progressDialog.setTitle("Contacting Servers");
        progressDialog.setMessage("Logging in ...");
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(true);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(String... args)
    {



        System.out.println("Doinbackground entered!");

        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("questionno",String.valueOf(questionno)));
        params.add(new BasicNameValuePair("surveyno",String.valueOf(surveyno)));


        JSONObject json = jsonParser.makeHttpRequest("http://www.tikox.com/ws/survey.php","POST", params);
        System.out.println("json object made, php should exec now!" + json.toString());

        Log.d("Create Response", json.toString());
        try {
            int success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                System.out.println(" Details fetched Successfully!");
                String msg = json.getString("message");
                System.out.println(" msg " + msg);



                que = json.getString("question");
                System.out.println(" que " + que);
                opt1 = json.getString("option1");
                System.out.println(" opt1 " + opt1);
                 opt2 = json.getString("option2");
                System.out.println(" opt2 " + opt2);
                 opt3 = json.getString("option3");
                System.out.println(" opt3 " + opt3);
                 opt4 = json.getString("option4");
                System.out.println(" opt4 " + opt4);

            }
            else
            {
                System.out.print("UnSuccessfull ");
                msg = json.getString("message");
                System.out.print(msg);

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                    }
                });

            }


        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }



    protected void onPostExecute(String file_url)
    {

        progressDialog.dismiss();
        survey.setText(que);
        optn1.setText(opt1);
        optn2.setText(opt2);
        optn3.setText(opt3);
        optn4.setText(opt4);
    }
}
}
公共类调查活动扩展活动{
按钮提交,conti,nextbtn;
文本视图头,调查,optn1,optn2,optn3,optn4;
字符串que、opt1、opt2、opt3、opt4;
复选框1、复选框2、复选框3、复选框4;
int surveyno=127;
int问题编号=1;
公共最终静态字符串标记_SUCCESS=“SUCCESS”;
公共静态最终字符串EXTRA_MESSAGE=“MESSAGE”;
串味精;
私人对话;
JSONParser JSONParser=新的JSONParser();
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_survey);
提交=(按钮)findViewById(R.id.btnsubit);
conti=(按钮)findViewById(R.id.btncontinue);
head=(TextView)findViewById(R.id.tvproject);
nextbtn=(按钮)findViewById(R.id.btnsubmtnxt);
调查=(TextView)findViewById(R.id.tvsurvey);
optn1=(TextView)findViewById(R.id.tVotOne);
optn2=(TextView)findViewById(R.id.tvopttwo);
optn3=(TextView)findViewById(R.id.tVopThree);
optn4=(TextView)findViewById(R.id.tvoptfour);
checkBox1=(复选框)findViewById(R.id.chkopt1);
checkBox2=(复选框)findViewById(R.id.chkopt2);
checkBox3=(复选框)findViewById(R.id.chkopt3);
checkBox4=(复选框)findViewById(R.id.chkopt4);
nextbtn.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v)
{
做
{
新建FetchQuestion().execute();
问题号++;
}而(问题号>=22);
}
});
//字体
Typeface type01=Typeface.createFromAsset(getAssets(),“HelveticaNeue UltraLight.ttf”);
head.setTypeface(type01);
submit.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
Intent fours1=新Intent(SurveyActivity.this,BeginAction.class);
星触觉(fours1);
}
});
conti.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
Intent fours1=新Intent(SurveyActivity.this,EntrpNxtStart.class);
星触觉(fours1);
}
});
新建FetchQuestion().execute();
}
公共无效链接DN(视图)
{
Intent Intent=新的Intent(Intent.ACTION\u视图,Uri.parse(“https://www.linkedin.com"));
星触觉(意向);
}
公开作废facebook(查看)
{
Intent Intent=新的Intent(Intent.ACTION\u视图,Uri.parse(“https://www.facebook.com"));
星触觉(意向);
}
公共void twitter(视图)
{
Intent Intent=新的Intent(Intent.ACTION\u视图,Uri.parse(“https://twitter.com/"));
星触觉(意向);
}
公共void insta(视图)
{
Intent Intent=新的Intent(Intent.ACTION\u视图,Uri.parse(“https://www.instagram.com/"));
星触觉(意向);
}
类FetchQuestion扩展了异步任务
{
私有进程对话;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
progressDialog=新建progressDialog(SurveyActivity.this);
progressDialog.setTitle(“联系服务器”);
progressDialog.setMessage(“登录…”);
progressDialog.setUndeterminate(false);
progressDialog.setCancelable(真);
progressDialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…args)
{
System.out.println(“输入Doinbackground!”);
List params=new ArrayList();
params.add(新的BasicNameValuePair(“questionno”,String.valueOf(questionno)));
params.add(新的BasicNameValuePair(“surveyno”,String.valueOf(surveyno)));
JSONObject json=jsonParser.makeHttpRequest(“http://www.tikox.com/ws/survey.php“,”POST“,params);
System.out.println(“生成json对象,php应该立即执行!”+json.toString());
d(“创建响应”,json.toString());
试一试{
int success=json.getInt(TAG_success);
如果(成功==1){
System.out.println(“已成功获取详细信息!”);
String msg=json.getString(“消息”);
System.out.println(“msg”+msg);
que=json.getString(“问题”);
System.out.println(“que”+que);
opt1=json.getString(“option1”);
System.out.println(“opt1”+opt1);
opt2=json.getString(“option2”);
系统输出打印项次(“opt2”+opt2);
opt3=json.getString(“option3”);
系统输出打印项次(“opt3”+opt3);
opt4=json.getString(“option4”);
系统输出打印项次(“opt4”+opt4);
}
其他的
{
系统输出打印(“未成功”);
msg=json.getString(“消息”);
系统输出打印(msg);
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
Toast.makeText(getApplicationContext(),msg,Toast.LENGTH_LONG.show();
}
});
}
}捕获(JSONException e){
e、 printStackTrace();
}
返回null;
}
受保护的void onPostExecute(字符串文件\u url)
{
progressDialog.disclose();
调查.setText(que);
optn1.setText(opt1);
optn2.setText(opt2);
optn3.setText(opt3);
optn4.setText(opt4);
}
}
}
选中
复选框
checkBox1.setChecked(false);
checkBox2.setChecked(false);
checkBox3.setChecked(false);
checkBox4.setChecked(false);
protected void onPostExecute(String file_url)
    {
        checkBox1.setSelected(false);
        checkBox2.setSelected(false);
        checkBox3.setSelected(false);
        checkBox4.setSelected(false);

        progressDialog.dismiss();
        survey.setText(que);
        optn1.setText(opt1);
        optn2.setText(opt2);
        optn3.setText(opt3);
        optn4.setText(opt4);
    }