Skip to content

Commit

Permalink
fix(settings):the position of cursor is not correct for some inouts
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Aug 20, 2022
1 parent 5e1e584 commit c326480
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/src/main/java/com/zcshou/gogogo/FragmentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.text.InputType;
import android.text.Selection;
import android.text.TextUtils;

import androidx.preference.EditTextPreference;
Expand Down Expand Up @@ -52,7 +53,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
return "当前值: " + text;
});
pfWalk.setOnBindEditTextListener(editText -> editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER));
pfWalk.setOnBindEditTextListener(editText -> {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
}

EditTextPreference pfRun = findPreference("setting_run");
Expand All @@ -64,7 +68,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
return "当前值: " + text;
});
pfRun.setOnBindEditTextListener(editText -> editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER));
pfRun.setOnBindEditTextListener(editText -> {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
}
EditTextPreference pfBike = findPreference("setting_bike");
if (pfBike != null) {
Expand All @@ -75,7 +82,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
return "当前值: " + text;
});
pfBike.setOnBindEditTextListener(editText -> editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER));
pfBike.setOnBindEditTextListener(editText -> {
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
Selection.setSelection(editText.getText(), editText.length());
});
}

SwitchPreferenceCompat pLog = findPreference("setting_log_off");
Expand Down

0 comments on commit c326480

Please sign in to comment.