0

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?

  • What is it that you try to accomplish? – greenapps Dec 10 '17 at 19:40
  • It will be a feature that allow users to use an app without adds. EditText receives string, compare it to the pattern and if maches icon changes (and ads dissapears). –  Dec 10 '17 at 19:46
  • I asked how your code should work. How your class should work. What would be different from a usual EditTextPreference. And EditTextPreferences usually do not come with adds so your answer is pretty strange. – greenapps Dec 10 '17 at 19:57
  • Now I simplified code to minimum. This code differs from base EditTextPreference with its behavoiur because I want to change the src of ImageView on the list when string from EditText matches to other one. This preference on the list besides the title and summary has ImageView on the right side also what is result of custom layout.
    /n But this all doesn't matter. Simple question. Why doesn't this simple code invoke a dialog with EditText and two buttons (yes/no) as it should ?
    –  Dec 10 '17 at 20:26
  • I do not understand that you create a new EditText. A nirmal EditTextPreference would already show one. A durived class would show one too. So why are you doing thi? Explain your code! – greenapps Dec 10 '17 at 21:24
  • At this time this code do nothing. I'm new at Android development and just testing new things. Now I just want to try to make this class fully work that is to display dialog with EditText area but as I said this dialog has only title and two buttons. So the question is how to define the simplest extending EditTextPreference class to make it work? –  Dec 11 '17 at 17:06
  • `android:layout="@layout/preference_auth"/>`. Please post the xml file. Does it have any effect? – greenapps Dec 12 '17 at 13:21
  • You can add a custom layout to a . See example here: https://stackoverflow.com/questions/6194116/creating-a-custom-layout-for-preferences – greenapps Dec 12 '17 at 14:50

1 Answers1

0

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.

  • It's good to hear that you found the cause of your problem. You could make your answer more helpful for future readers by explaining *how* you diagnosed it, and in particular, which evidence will identify this problem when it's seen elsewhere. – Toby Speight Dec 12 '17 at 14:24