Anonymous
Anonymous

Reputation: 37

How to get value of checkbox into textview in Eclipse Android?

I already made multiple checkbox in dialog and want to get the checkbox value to textview in another activity, but i don't know the code, anyone can help?

Upvotes: 3

Views: 717

Answers (2)

Sonia John Kavery
Sonia John Kavery

Reputation: 2129

Try the following.

CheckBox cb=(CheckBox)findViewById(R.id.checkbox1);
TextView tv=(TextView)findViewById(R.id.textview1);
cb.setOnClickListener(new OnClickListener() {

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

                if(cb.isChecked()){
                    cb.setChecked(true);
                    tv.setText(cb.getText().toString());
                }
            }
        });

If you want to use it in another activity,either you can save it in local storage like sharedpreference or to a global variable.

Upvotes: 2

Hardik Parmar
Hardik Parmar

Reputation: 712

first you get the value form the check box like ..

if (chk_Other_friOff.isChecked()) {
        Global.newOther_fir = "1";
        Log.e("Check box", "1st May ;;;" + Global.newOther_fir);
    } else {
        Global.newOther_fir = "0";
    }
    if (chk_Other_satOff.isChecked()) {
        Global.newOther_sat = "1";
    } else {
        Global.newOther_sat = "0";
    }
    if (chk_Other_decOff.isChecked()) {
        Global.newOther_dec = "1";
    } else {
        Global.newOther_dec = "0";
    }
    if (chk_Other_phone.isChecked()) {
        Global.newOther_phone = "1";
    } else {
        Global.newOther_phone = "0";
    }

Hear is Global is store a static value from conman class in my application. and is get to another Activity like

TextView tv;
tv.setText(Global.newOther_phone);

its very simple.

Thanks...

Upvotes: 0

Related Questions