I used a simple solution and it works, although I don't know if that's the best way to do it.
YesNo class:
package com.me.myapp;
public class YesNo extends DialogPreference
{
public YesNo(Context context, AttributeSet attrs)
{
super(context, attrs);
}
@Override
protected void onClick()
{
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
dialog.setTitle("Reset application?");
dialog.setMessage("This action will delete all your data. Are you sure you want to continue?");
dialog.setCancelable(true);
dialog.setPositiveButton("Delete", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
//reset database
Toast.makeText(getContext(), "Application reset!", Toast.LENGTH_SHORT).show();
}
});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dlg, int which)
{
dlg.cancel();
}
});
AlertDialog al = dialog.create();
al.show();
}
}
and the preference in the XML file:
<com.me.myapp.YesNo
android:title="Reset application"
android:summary="Delete all data"
/>