question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextInputLayout] Focus between TextInputEditText and multiple fragments

See original GitHub issue

Description: I have 2 fragments. Xml are the same, contain 3 TextInputLayout.

When I am on Fragment2, I enter the text in fieldFour, I press enter on the keyboard, I expect the cursor to move to fieldFive, but it does not work. I think the cursor falls into the fields of Fragment1. How to fix this? I tried If to use EditTexts all cursor transitions work correctly.

If one fragment with the TextInputLayout set has been added. Cursor transitions from one TextInputLayout to another are performed correctly Thanks.

Source code:

 supportFragmentManager.beginTransaction()
        .add(R.id.frame, Fragment1())
        .addToBackStack("Fragment1")
        .commit()

    supportFragmentManager.beginTransaction()
        .add(R.id.frame, Fragment2())
        .addToBackStack("Fragment2")
        .commit()

xml Fragment1

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="fragment1" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/fieldOne"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/fieldTwo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/fieldThree"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

</LinearLayout>

xml Fragment2

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="fragment2" />

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/fieldFour"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/fieldFive"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/fieldSix"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:maxLines="1" />

    </com.google.android.material.textfield.TextInputLayout>

</LinearLayout>

Android API version: API 29

Material Library version: I use 1.1.0, but there is also 1.2.0-alpha05

Device: Nokia 3.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hunterstichcommented, Apr 13, 2020

Hey there. Thanks for reporting.

Can you use something like android:imeOptions="actionNext" android:nextFocusForward="@+id/.." to solve this?

0reactions
hunterstichcommented, Apr 17, 2020

Great. Going to go ahead and close this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - 2 hints appearing when TextInputLayout is focused
To solve the issue, just remove the FragmentTrancaction.replace from your main activity and let the Nav Component load up the fragment for you....
Read more >
Android TextInputLayout Example | DigitalOcean
Android TexInputLayout extends LinearLayout. The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and ...
Read more >
TextInputLayout | Android Developers
Layout which wraps a TextInputEditText , EditText , or descendant to show a floating label when the hint is hidden while the user...
Read more >
Material Design Edit Text | Android Studio Tutorial - YouTube
TextInputEditText - Material Design Edit Text | Android Studio Tutorial · Chapters. View all · Chapters · Description · Chapters. View all ·...
Read more >
TextInputLayout not showing hint until focused [37048478]
When an EditText (or AppCompatEditText) is wrapped in a TextInputLayout, the hint does not show until the EditText is focused.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found