Android : Select all the option in android

on Tuesday, April 14, 2015



public class SignUpTwo extends Base2_Activity {
public static final String PROPERTY_REG_ID = "registration_id";
Button nextsignup2_show;
Button gobacksignup2_show;
CheckBox chkBox1, chkBox6,chkBox8;



@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.signup2);
chkBox1 = (CheckBox) findViewById(R.id.checkBox1);
chkBox1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(((CheckBox) v). isChecked()){
Toast.makeText(SignUpTwo.this, "Selected", Toast. LENGTH_SHORT). show();
}

else{
Toast.makeText(SignUpTwo.this, "Not Selected", Toast. LENGTH_SHORT). show();
}
}
});
chkBox6 = (CheckBox) findViewById(R.id.checkBox6);
chkBox6.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(((CheckBox) v). isChecked()){
Toast.makeText(SignUpTwo.this, "Selected", Toast. LENGTH_SHORT). show();
}

else{
Toast.makeText(SignUpTwo.this, "Not Selected", Toast. LENGTH_SHORT). show();
}
}
});
chkBox8 = (CheckBox) findViewById(R.id.checkBox8);
chkBox8.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(((CheckBox) v). isChecked()){
Toast.makeText(SignUpTwo.this, "Selected", Toast. LENGTH_SHORT). show();
}

else{
Toast.makeText(SignUpTwo.this, "Not Selected", Toast. LENGTH_SHORT). show();
}
}
});




nextsignup2_show=(Button) findViewById(R.id.buttonnext);


nextsignup2_show.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

new PostDataAsyncTask().execute();



}
});



}

public class PostDataAsyncTask extends AsyncTask<String, String, String>
{

@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String resresult=null;
try {

resresult = postText();

} catch (NullPointerException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

return resresult;
}


@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
System.out.println(result);
Intent i= new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);

}


}


private String postText(){

String responseStr=null;
try{

String postReceiverUrl = "http://10.0.2.2:8080/a/insert1.php";

HttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost(postReceiverUrl);

MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();

entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entityBuilder.addTextBody("regId", GlobalVar.id);
if(chkBox1.isChecked()){
entityBuilder.addTextBody("all", chkBox1.getText().toString());
}
if(chkBox6.isChecked()){
entityBuilder.addTextBody("education", chkBox6.getText().toString());}

if(chkBox8.isChecked()){
entityBuilder.addTextBody("movies", chkBox8.getText().toString());}

HttpEntity entity = entityBuilder.build();
post.setEntity(entity);

HttpResponse response = client.execute(post);


HttpEntity resEntity = response.getEntity();

if (resEntity != null) {

responseStr = EntityUtils.toString(resEntity).trim();
// Log.v(TAG, "Response: " + responseStr);

}

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return responseStr;
}

}


Here i can check the boxes individually. However I want to check all the boxes together. That means when I will press all all the checkboxes will be checked. However, its not happening in amy android packages. How can I do that one.


0 comments:

Post a Comment