I have preferences.xml which is used in my extension of PreferencesActivity.
I have another preference in the xml that I would like to use to clear the cache of a w
Solved by adding:
Preference myPref = findPreference("myPref");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
MyActivity.mWebView.clearCache(true);
return false;
}
});
Thanks for your own answer :) It was usefull for me.
In addition: below is the code when you want to delete a directory/folder on the sd-card from your xml-style preferences:
public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
Preference myPref = findPreference("myPref");
myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
File sdcard = Environment.getExternalStorageDirectory();
String sdcardPath = sdcard.getAbsolutePath();
File mDbFile = new File(sdcardPath + "/myPath/");
if(mDbFile.exists()) {
deleteDirectory(mDbFile);
}
return false;
}
});
}
private static boolean deleteDirectory(File path) {
if( path.exists() ) {
File[] files = path.listFiles();
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
return( path.delete() );
}
}