0

In my application I am trying to send data to server, data is sending properly and I am getting successful message from response,but I dont know how to send value of radio button,because in server data is not storing,see my previous question https://stackoverflow.com/questions/27311273/how-to-find-value-of-radio-button-same-like-html

public class Filter extends Activity{

private TextView sp;
private EditText tv;
private ImageView b;
private TextView sp1;
private TextView agefrom;
private TextView ageto;
private RadioGroup rdgrp;
private RadioButton rdall;
private RadioButton rdfilter;
private LinearLayout linfirst;
private LinearLayout linsecond;
private TextView spmrg;
static Dialog d ;
String USERLOGINID;
// Progress Dialog
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private ImageView saves;
private static final String FILTER_URL = "";
private static final String FILTER_SUCCESS = "status";
private static final String FILTER_LOGIN = "msg";
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.filter);
    USERLOGINID=this.getIntent().getStringExtra("id");
    System.out.println("Filter"+USERLOGINID);
    sp=(TextView)findViewById(R.id.spinnerfilterdetailmothertong);
    sp1=(TextView)findViewById(R.id.spinnerfilterdetaicountry);
    spmrg=(TextView)findViewById(R.id.spinnerfiltermarrage);
    agefrom=(TextView)findViewById(R.id.spinneragefilterfrom);
    ageto=(TextView)findViewById(R.id.spinneragefilterto);
    rdgrp=(RadioGroup)findViewById(R.id.radioGender);
    rdall=(RadioButton)findViewById(R.id.allowall);
    rdfilter=(RadioButton)findViewById(R.id.allowfilter);
    linfirst=(LinearLayout)findViewById(R.id.linearlayoutfilter);
    linsecond=(LinearLayout)findViewById(R.id.linearsecondpart);
    saves=(ImageView)findViewById(R.id.btnreg);
    linfirst.setVisibility(View.GONE);
    linsecond.setVisibility(View.GONE);

    rdgrp.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // TODO Auto-generated method stub
            int id=rdgrp.getCheckedRadioButtonId();
              View radioButton = rdgrp.findViewById(id);
              if(radioButton.getId()==R.id.allowall)
              {
                  linfirst.setVisibility(View.GONE);
                linsecond.setVisibility(View.GONE);
              }
              else
              {
                  linfirst.setVisibility(View.VISIBLE);
                linsecond.setVisibility(View.VISIBLE);
              }
        }
    });

    final String[] mrgstatus = new String[] {"Married", "Never Married", "Divorced","Seperated","Widow/Widower"};
    final ArrayAdapter<String> adaptermrgstatus = new ArrayAdapter<String>(Filter.this,
            android.R.layout.simple_spinner_dropdown_item, mrgstatus);
    spmrg.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View w) {
              new AlertDialog.Builder(Filter.this)
              .setTitle("Select")
              .setAdapter(adaptermrgstatus, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    spmrg.setText(adaptermrgstatus.getItem(which).toString());

                  dialog.dismiss();
                }
              }).create().show();
            }
    });

    final String[] country = new String[] {"Afganistan", "Albania", "Algeria","India","Pakistan"};
    final ArrayAdapter<String> adaptercountry = new ArrayAdapter<String>(Filter.this,
            android.R.layout.simple_spinner_dropdown_item, country);
    sp1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View w) {
              new AlertDialog.Builder(Filter.this)
              .setTitle("Select")
              .setAdapter(adaptercountry, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    sp1.setText(adaptercountry.getItem(which).toString());

                  dialog.dismiss();
                }
              }).create().show();
            }
    });

    final String[] langs = new String[] {"Afganistan", "Albania", "Algeria","India","Pakistan"};
    final ArrayAdapter<String> adapterlangs = new ArrayAdapter<String>(Filter.this,
            android.R.layout.simple_spinner_dropdown_item, langs);
    sp.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View w) {
              new AlertDialog.Builder(Filter.this)
              .setTitle("Select")
              .setAdapter(adapterlangs, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    sp.setText(adapterlangs.getItem(which).toString());

                  dialog.dismiss();
                }
              }).create().show();
            }
    });

    final String[] catagory = new String[] {"18", "19", "20","21","22", "23","24","25","26","27", "28","29","30","31","32", "33","34","35","36","37", "38","39","40","41","42", "43","44","45","46","47", "48","49","50","51","52", "53","54","55","56","57", "58","59","60","61","62", "63","64","65","66","67", "68","69","70"};
    final ArrayAdapter<String> adapteragefrom = new ArrayAdapter<String>(Filter.this,
            android.R.layout.simple_spinner_dropdown_item, catagory);
    agefrom.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View w) {
              new AlertDialog.Builder(Filter.this)
              .setTitle("Select")
              .setAdapter(adapteragefrom, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    agefrom.setText(adapteragefrom.getItem(which).toString());

                  dialog.dismiss();
                }
              }).create().show();
            }
    });
    final String[] agetoo = new String[] {"18", "19", "20","21","22", "23","24","25","26","27", "28","29","30","31","32", "33","34","35","36","37", "38","39","40","41","42", "43","44","45","46","47", "48","49","50","51","52", "53","54","55","56","57", "58","59","60","61","62", "63","64","65","66","67", "68","69","70"};
    final ArrayAdapter<String> adapterageto = new ArrayAdapter<String>(Filter.this,
            android.R.layout.simple_spinner_dropdown_item, agetoo);
    ageto.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View w) {
              new AlertDialog.Builder(Filter.this)
              .setTitle("Select")
              .setAdapter(adapterageto, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    ageto.setText(adapterageto.getItem(which).toString());

                  dialog.dismiss();
                }
              }).create().show();
            }
    });
    saves.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            new AttemptLogin().execute();
            rdall.setChecked(true);
        }
    });

}
class AttemptLogin extends AsyncTask<String, String, String> {
    boolean failure = false;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Filter.this);
        pDialog.setMessage("Processing..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @SuppressWarnings("unused")
    @Override
    protected String doInBackground(String...args) {
        //Check for success tag
        //int success;
        Looper.prepare();
        String userloginid=USERLOGINID.toString();
        String allowall=rdall.toString();
        String mothertongue = sp.getText().toString();
        String marital=spmrg.getText().toString();
        String agefroms=agefrom.getText().toString();
        String agetos=ageto.getText().toString();
        String contry=sp1.getText().toString();
         try {
             List<NameValuePair> params = new ArrayList<NameValuePair>();
             params.add(new BasicNameValuePair("user_login_id", userloginid));
             params.add(new BasicNameValuePair("all_allow", allowall));
             params.add(new BasicNameValuePair("moth_tong", mothertongue));
             params.add(new BasicNameValuePair("maritalstatus", marital));
             params.add(new BasicNameValuePair("age_from", agefroms));
             params.add(new BasicNameValuePair("age_to", agetos));
             params.add(new BasicNameValuePair("country", contry));
             params.add(new BasicNameValuePair("version", "apps"));

             Log.d("request!", "starting");
             // getting product details by making HTTP request
            JSONObject json = jsonParser.makeHttpRequest (
                 FILTER_URL, "POST", params);
             //check your log for json response
             Log.d("Request attempt", json.toString());
             final String str = json.toString();
             JSONObject jobj = new JSONObject(json.toString());
             final String msg = jobj.getString("msg");
             System.out.println("MSG : " + msg);
             runOnUiThread(new  Runnable() 
             {
                @Override
                public void run() 
                {
                    Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
                } 
            });

             return json.getString(FILTER_SUCCESS);

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

    // After completing background task Dismiss the progress dialog

    protected void onPostExecute(String file_url) {
        //dismiss the dialog once product deleted
         pDialog.dismiss();
}}

}

Community
  • 1
  • 1

2 Answers2

0

Have you tried to get the selected id in your asynctask doInBackground

int id=rdgrp.getCheckedRadioButtonId();

right after

String contry=sp1.getText().toString();

then add the result in the parameters, something like that:

 params.add(new BasicNameValuePair("choice", id+""));

You can also define a global variable in your activity that the Asynctask can access.

arthur_gg
  • 279
  • 1
  • 8
0

first store the value of radio button in a variable when it is selected or by using setOnCheckedChangeListener. use this answer Android getting value from selected radiobutton

then use that variable in your async task to get the text from it.

Community
  • 1
  • 1
Amrut Bidri
  • 6,276
  • 6
  • 38
  • 80