I've been scratching my head over this for a few nights now. I cannot seem to get an EditText (set as a view for an AlertDialog) to automatically spell check when entering text, even though I know spell check is enabled because it's working elsewhere:
error showing spell check not working
I've seen several posts where the dev wants spellcheck disabled, but none where it wasn't working that have any resolution. Is this something disabled because I'm using an AlertDialog (EditTexts elsewhere are working), and if so, is there any kind of workaround or any other solution besides an AlertDialog that I can try?
Here is my code:
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final EditText input = new EditText(getActivity());
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES|InputType.TYPE_TEXT_FLAG_AUTO_CORRECT|InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE); //I have tried all combinations of InputType options, including no options.
input.setSingleLine(false);
input.setMaxLines(6);
input.setText("Some Default Text");
input.setSelectAllOnFocus(true);
input.requestFocus();
builder.setView(input);
builder.show();
UPDATE:
I just tried inflating the following layout file:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtJournalSummaryLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Please summarize your experience studying:"
android:textAlignment="center"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/txtJournalNewSummary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="6"
android:minLines="3"
android:singleLine="false"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtJournalSummaryLabel" />
</android.support.constraint.ConstraintLayout>
to the AlertDialog:
View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_journal_summary_prompt, null);
final EditText txtInput = view.findViewById("Some Default Text");
txtInput.setText(this.journalTitles.get(0));
builder.setView(view);
But the AlertDialog is still not showing spelling errors. Is this because the view is not attached to the parent Activity/Fragment? Any help would be greatly appreciated.
Figured out a solution. For some reason, when directly inserting the EditText into the builder and then apply the textAutoCorrect flag for inputType, spell check would not work.
image showing autocorrect working
The solution was to create a layout file with the EditText (see modified question above), but make sure to enable the textAutoCorrect flag in the xml resource file, apply the inflated view to the AlertDialog builder, then watch it work.
I wish it would automatically auto-correct what was manually placed in their (previous value), but this works well enough for me. Leaving my solution for posterity.