Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android setError() message scrolling on top of ActionBar

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: http://imgur.com/fG8bd3E,uFzhOXa#1 <- 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));
like image 652
Sagar Avatar asked Jun 24 '13 01:06

Sagar


3 Answers

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

like image 185
Ihor DIM Avatar answered Nov 10 '22 09:11

Ihor DIM


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)
);}
like image 24
Albert Avatar answered Nov 10 '22 09:11

Albert


I resolve similiar problem by setting flag

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
like image 1
Ewa Kropkowska Avatar answered Nov 10 '22 09:11

Ewa Kropkowska