I'm developing a simple app for learning purpose, In which there is a single check box and a text line, which shows it is checked or unchecked. But it shows an error in line setContentView(R.layout.main)
and cb=(CheckBox)findViewById(R.id.check)
this is my java code:
package com.example.kaushal.checkbox;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.R;
public class Checkbox extends Activity
implements CompoundButton.OnCheckedChangeListener {
CheckBox cb;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
cb=(CheckBox)findViewById(R.id.check);
cb.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
cb.setText("This checkbox is: checked");
}
else {
cb.setText("This checkbox is: unchecked");
}
}
}
It is not a duplicate question,I've seen the answers of the same questions but it was all for eclipse.I'm working with android studio.
My activity_ckeckbox.xml file has no errors.I'm new to android so please guide me.
Aucun commentaire:
Enregistrer un commentaire