13

My issue is that the error message in my EditTexts are scrolling on top of the action bar. Is this an android bug, or am I doing something wrong?

Also this bug happens even when the keyboard is down, it just happens to be up in the screenshots.

Here is what I am talking about: https://i.stack.imgur.com/XsVEQ.png <- there are two images

Here is my layout, I add the EditTexts in my code to the kiosk_form_table LinearLayout

<ScrollView
    style="@style/DefaultBackground"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="0.6"
    android:fadeScrollbars="false"
    android:padding="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingRight="20dp" >

        <LinearLayout
            android:id="@+id/kiosk_form_table"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />

        <Button
            android:id="@+id/kiosk_submit_large"
            style="@style/LoginButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:onClick="submit"
            android:text="@string/submit" />
    </LinearLayout>
</ScrollView>

How I add the EditTexts

kiosk_form.addView(getKioskRow(R.layout.kiosk_text_row, "First Name", true, null));

private View getKioskRow(int layout, String header, boolean required, String buttonName)
{
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(layout, null);
    view.setTag(required);
    addHeader((TextView) inflater.inflate(R.layout.field_header, null), header);
    if (required)
        ((TextView) view.findViewById(R.id.kiosk_input)).setHint("Required");
    if (buttonName != null)
        ((Button) view.findViewById(R.id.kiosk_input_button)).setText(buttonName);
    return view;
}

private void addHeader(TextView view, String header)
{
    view.setTag(false);
    view.setText(header);
    kiosk_form.addView(view);
}

How I set the error

(TextView) view).setError(getString(R.string.error_field_required));
Sagar
  • 133
  • 1
  • 5

4 Answers4

4

It is Android OS bug. You can track its progress here

Ihor DIM
  • 689
  • 1
  • 10
  • 22
3

I had the same problem. Solved it like this:

private void processingErrorPopupsWhenScrolling(Rect scrollBounds, TextInputEditText... views) {
    boolean isViewInFocus = false;
    for (TextInputEditText textInputEditText : views) {
        if (textInputEditText.getError() != null) {
            if (textInputEditText.getLocalVisibleRect(scrollBounds)) {
                textInputEditText.setVisibility(View.VISIBLE);

                if (!isViewInFocus) {
                    textInputEditText.requestFocus();
                    isViewInFocus = true;
                }
            } else {
                textInputEditText.setVisibility(View.INVISIBLE);
            }
        }
    }
}

// in onCreate(){
Rect scrollBounds = new Rect();
mScrollView.getHitRect(scrollBounds);

mScrollView.getViewTreeObserver().addOnScrollChangedListener(() ->
        processingErrorPopupsWhenScrolling(scrollBounds,
                mLink,
                mTitle,
                mPrice)
);}
Albert
  • 163
  • 2
  • 7
1

I resolve similiar problem by setting flag

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Ewa Kropkowska
  • 103
  • 1
  • 8
0

Where do you want to see the error message? If you want it on EditText, set it on editText.

((EditText) findViewByID(R.id.my_edit_text)).setError ...... // and so on

Edit: original answer didn't help.

Here's one possible solution: you can hide the error message when the user is scrolling the view. When the scroll has finished you can re-set the error message and it should appear in the right spot! Here's how you can detect when a scroll finished: Android: How to detect when a scroll has ended

Community
  • 1
  • 1
Oleksiy
  • 37,477
  • 22
  • 74
  • 122
  • I want my error messages to appear on a variety of views that are all a subclass of TextView so if you look at my last code snippet I add an error message to my views, some of which are edit texts. My issue is not that the error is not showing up. My error is that when I scroll, the pop up message goes on top of the action bar as seen in my imgur link (I am new to the community, so I don't have enough reputation to embed the link). – Sagar Jun 24 '13 at 01:48
  • Ohhh ok I get it. Here's one possible solution: you can hide the error message when the user is scrolling the view. When the scroll has finished you can re-set the error message and it should appear in the right spot! Here's how you can detect when a scroll finished: http://stackoverflow.com/questions/2089552/android-how-to-detect-when-a-scroll-has-ended – Oleksiy Jun 24 '13 at 01:56
  • Hmm, I can see that working. Just out of curiosity do you know a quick to turn off all error messages, or if that is even possible. I ask because right now I loop through a large amount of views to populate that form and I would like to avoid having to loop through the list to turn off error messages every time the user scrolls. Regardless thanks for the help! – Sagar Jun 24 '13 at 02:26
  • 1
    I don't know if you can turn them off all at once. But you could save references to the views that have error messages displayed on them (in an array or something). Then you don't have to loop through everything, just do the ones that display errors. – Oleksiy Jun 24 '13 at 03:42
  • That should work, thanks! I wish I could upvote things but I have no reputation :(. – Sagar Jun 24 '13 at 14:13
  • @Oleksiy On the link you gave, what are `handleDoubleTap(e)` and `handleSingleTap(e)`? How do I use `initGestureDetection` to detect if the scroll has finished? – Compaq LE2202x Nov 21 '13 at 01:46
  • @Oleksiy, how do capture(reference) the popup error message you want to disable on scroll? I'm having the same problem. – Nactus Sep 30 '15 at 20:36
  • This should be handled by android. – user2934930 May 04 '21 at 18:22