Reputation: 27
hello am trying to implement an onclick event for CheckBoxPreference. In the folder res/xml/preferences.xml i have this preference:
<CheckBoxPreference
android:key="IsEnable"
android:title="IsEnable"
android:persistent="true"
/>
i followed this answer on SO: Android preferences onclick event
In the activity.java:
public class settingsActivity extends SherlockPreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference myPref = (Preference) findPreference("IsEnable");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {//<--compilation error
public boolean onPreferenceClick(Preference preference) {
//code goes here
return true;
}
});
}
But am getting the below compile error at the 7th line: Multiple markers at this line - OnPreferenceClickListener cannot be resolved to a type - The method setOnPreferenceClickListener(Preference.OnPreferenceClickListener) in the type Preference is not applicable for the arguments (new OnPreferenceClickListener(){})
Thank you for your help.
Upvotes: 0
Views: 2813
Reputation: 6108
You need to import it too? Check if you have this line
import android.preference.Preference.OnPreferenceClickListener;
Upvotes: 3