I was trying to use setOnBindEditTextListener to EditTextPreference, but it says that it cannot resolve the method. Where is the problem?
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import static com.chemistryApps.Constants.NUMBER_OF_QUESTIONS_GUESS_FORMULA;
import static com.chemistryApps.Constants.NUMBER_OF_QUESTIONS_GUESS_NAME;
public class SettingsFragment extends PreferenceFragmentCompat {
private SettingsFragment.OnPreferenceInteractionListener mListener;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.pref_general,rootKey );
EditTextPreference preference =
(EditTextPreference) this.findPreference("first_question");
preference.setOnBindEditTextListener(new EditTextPreference.OnBindEditTextListener() {
@Override
public void onBindEditText(@NonNull EditText editText) {
editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
}
});
It showed up that I needed to implement the preference library from android separately. Even though all other Preference methods worked.
implementation "androidx.preference:preference:$preference_version"