I have settings Activity with list of preferences from R.xml.preferences. One of the preferences here looks like this:
<AuthPreference
android:title="@string/auth_title"
android:summary="@string/auth_summary"
android:key="pass"
android:defaultValue="1"
android:dialogMessage="Provide a message"
android:layout="@layout/preference_auth"/>
This preference extends EditTextPreference class so I expected this to show EditText area after the preference is clicked. But there is just empty dialog with no and yes buttons only. The code is shown below:
public class AuthPreference extends EditTextPreference {
private ImageView icon;
private EditText et;
public AuthPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setNegativeButtonText("no");
setPositiveButtonText("yes");
}
public AuthPreference(Context context, AttributeSet attrs) {
this(context, attrs, 0);
setNegativeButtonText("no");
setPositiveButtonText("yes");
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
icon = (ImageView) view.findViewById(R.id.iconSelected);
}
@Override
protected void onBindDialogView(View view) {
some code
}
}
What's wrong?
It turned out the second constructor was wrong because of passing the third arg to the immediate parent by super that was set to 0. So after changes I have
super(context, attrs);
instead of
super(context, attrs, 0);
You just need to be careful and make sure you pass corresponding args to specific parent's constructor.