If you think the Android project callmeter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package de.ub0r.android.callmeter.ui.prefs;
//fromwww.java2s.comimport android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.ListPreference;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.Toast;
import de.ub0r.android.callmeter.R;
publicclass BillModeListPreference extends ListPreference {
privatefinal Context ctx;
public BillModeListPreference(final Context context) {
super(context);
ctx = context;
}
public BillModeListPreference(final Context context, final AttributeSet attr) {
super(context, attr);
ctx = context;
}
@Override
protectedvoid onDialogClosed(finalboolean positiveResult) {
final String ov = getValue();
super.onDialogClosed(positiveResult);
if (positiveResult) {
String v = getValue();
if (v == null || !v.contains("/")) { // custom bill mode
Builder b = new Builder(getContext());
final EditText et = new EditText(getContext());
et.setText(ov);
b.setView(et);
b.setCancelable(false);
b.setTitle(getTitle());
b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
publicvoid onClick(final DialogInterface paramDialogInterface,
finalint paramInt) {
BillModeListPreference.this.setValue(ov);
}
});
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
publicvoid onClick(final DialogInterface dialog, finalint which) {
String nv = et.getText().toString().trim();
final String[] t = nv.toString().split("/");
if (t.length != 2 || !TextUtils.isDigitsOnly(t[0])
|| !TextUtils.isDigitsOnly(t[1])) {
Toast.makeText(BillModeListPreference.this.ctx, R.string.missing_slash,
Toast.LENGTH_LONG).show();
BillModeListPreference.this.setValue(ov);
} else {
BillModeListPreference.this.setValue(nv);
}
}
});
b.show();
}
}
}
}