2016-10-26 12 views
1

私はいくつかの質問をしなければならないアンケートアプリを実装しようとしています。だから私はCheckBoxを使っていますが、私が直面している問題は、次のボタンをクリックすると次の質問が画面に現れますが、最後の質問のためにチェックされたCheckBoxはまだ新しい質問がチェックされています。だから、私は次の質問のために次のボタンをクリックするときにCheckBoxをすべてクリアしたい。[次へ]ボタンをクリックしてもチェックボックスがクリアされない

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); 
    } 
} 
} 

答えて

0

あなたはかつて次のクリックされたチェックボックスをオフにする必要があります。 onPostExecute()に以下のコードを追加してください。次のクリックリスナーで

checkBox1.setChecked(false); 
checkBox2.setChecked(false); 
checkBox3.setChecked(false); 
checkBox4.setChecked(false); 
+0

のためにそんなにセルジオありがとう!!!! – Techfreak

0

あなたが右のあなたのnextbtnクリックリスナーで使用できるsetChecked方法を持っているCompoundButtonからCheckBoxクラスを継承。

の例では、チェックボックスのためのAndroidのドキュメントにあります:https://developer.android.com/reference/android/widget/CheckBox.html

+0

のようにすべてのチェックボックスを選択解除...それは私のために働いたたくさんありがとう迅速な返信 – Techfreak

0

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); 
    } 
関連する問題