mardi 1 décembre 2015

I have basic three checkboxes so when iam unchecking single checkbox three checkboxes are getting unchecked? please provide me a solution

package com.example.checkbox;

import android.app.Activity; import android.os.Bundle; import android.os.Vibrator; import android.view.View; import android.widget.CheckBox; import android.widget.TextView;

public class MainActivity extends Activity { TextView tv; String text = ""; CheckBox cb1,cb2,cb3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cb1=(CheckBox)findViewById(R.id.cb1); cb2=(CheckBox)findViewById(R.id.cb2); cb3=(CheckBox)findViewById(R.id.cb3); tv = (TextView)findViewById(R.id.tv1); } public void display(View v) { boolean checked = ((CheckBox)v).isChecked(); int id = v.getId() switch (id) { case R.id.cb1: { if (checked) { text=cb1.getText().toString(); } else { text = ""; } break; } case R.id.cb2: {if(checked) {text =cb2.getText().toString(); } else { text = ""; } break; } case R.id.cb3: { if(checked) { text = cb3.getText().toString(); } else { cb3.setChecked(false); } } } tv.setText(text); } }




Aucun commentaire:

Enregistrer un commentaire