I’ve been trying to add some settings to my application for a couple of weeks now.
I really need the checkbox function.
I am trying to control the visibility of a single checkbox check box
Here is my Preferences.java
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.Preference.OnPreferenceChangeListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.view.View;
public class Preferences extends PreferenceActivity {
private RadioButton btn01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
btn01 = (RadioButton)findViewById(R.id.RadioButton01);
Preference customPref = (Preference) findPreference("customPref");
customPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(),
"The Custom Preference Has Been Clicked",
Toast.LENGTH_LONG).show();
SharedPreferences customSharedPreference = getSharedPreferences(
"myCutomSharedPrefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference
.edit();
editor.putString("myCustomPref",
"The preference has been clicked");
editor.commit();
return true;}
public void CheckBox() {
final CheckBox ThisCheckBox = (CheckBox) findViewById (R.id.checkboxPref);{
ThisCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public boolean OnCheckedChange (CompoundButton compoundButton) {
if (ThisCheckBox.isChecked()){
{
btn01.setVisibility(0);
}{
btn01.setVisibility(2);
}}
}
;
});
};}});}}
In any case, I am sure that this is completely wrong, and I get an error on this line
ThisCheckBox.setOnCheckedChangeListener (new OnCheckedChangeListener () {
any idea why? I think this is due to the way I named the line above, but whether I use a finite, logical, or void that still generates errors.
this error message
Type new CompoundButton.OnCheckedChangeListener () {} should implement the inherited abstract method CompoundButton.OnCheckedChangeListener.onCheckedChanged (CompoundButton, boolean)
So, I think I ask
Preferences Right
If else?