Scroll nestedscrollview to bottom of textView - android

I have some editText in my activity so put them into nestedScrollView and my activity has the adjustResize attribute.
I put a textView at bottom of each editText to show the exitText input error.
But their visibility are Gone.
When the soft-keyboard open I don't have a problem whit the first exitText, when I click on Next button of the soft-jetboard nestedScrollView scrolled to the bottom of next editText and if user write a wrong input to my editText the textView of them will be visible and show the error of input to the user.
BUT PROBLEM IS.
They are below of their editText.
How I can scroll nestedScrollView to the bottom of the textView?

You could just use TextInputEditText and TextInputLayout instead of EditText and TextView.
The scrolling behavior will be managed by Android's system and should result correctly.
Also, it will simplify your code:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
app:errorEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/text_input_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint"/>
</com.google.android.material.textfield.TextInputLayout>
You can set and remove errors with:
Java
text_input_layout.setError("Error message");
text_input_layout.setError(null);
Kotlin
text_input_layout.error = "Error message"
text_input_layout.error = null

Related

Stop ScrollView from auto-scrolling to an EditText when using ConstraintLayout

I`m have a problem just like this one:
Stop ScrollView from auto-scrolling to an EditText
I have Layout inside a ScrollView. In this layout there`s a lot of diffetent views (EditText, Spinners, etc...)
If a EditText has the focus and then I select a item from a Spinner, the display auto-scroll back to the EditText that have the focus.
Putting this code in the Layout parameters, solves the problem in most cases.
android:focusable="true"
android:focusableInTouchMode="true"
BUT...
My layout is a Constraint Layout and what is happening is that all EditText that have a 0dp ("match_constraint") size, or "match_parent" are still doing the auto-scroll to it. And the EditText that have a fixed size ou "wrap_content" works fine.
"This Layout is inside a ScrollView"
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
"This EditText, if have focus, make the auto-scroll to it"
<EditText
android:id="#+id/edtText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="someView"/>
"This EditText, if have focus, DO NOT make a auto-scroll to it"
<EditText
android:id="#+id/edtText2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="text"
app:layout_constraintTop_toBottomOf="#+id/edtText1"
app:layout_constraintStart_toStartOf="parent"/>
...
...
...
...
"Spinner at the end of Layout that i'm selecting a item..."
<Spinner....
Again... If I'm Using a Linear or Relative layout, the solution works fine... But when using the Constraint layout works for some EditText and others NOT, and the tests that I have made point to the fact that some EditText use a match_constraint size or somthing related to it..
Any one else having this same problem or able to replicate the problem that is happening here only with the Constraint layout ???
Thanks

EditText either editable or non editable and clickable

I have a RecyclerView with the following items layout:
<LinearLayout
android:orientation="horizontal"
....
android:clickable="#{viewModel.isClickable}"
android:onClick="#{viewModel::onPropertyClicked}">
<LinearLayout
....
android:clickable="false">
<TextView
android:clickable="false"
android:focusable="false"
.... />
<EditText
...
android:text="#{viewModel.propertyValue}"
android:focusable="#{viewModel.isEditTextClickable}"
android:focusableInTouchMode="#{viewModel.isEditTextClickable}"
android:cursorVisible="#{viewModel.isEditTextClickable}"
android:clickable="#{!viewModel.isEditTextClickable}"/>
</LinearLayout>
<ImageView ... />
</LinearLayout>
I want depending on a boolean the EditText to be either editable or non-editable and clickable. For some unknown reason, my EditText doesn't dispatch the touch event to the parent's parent. If I click on the TextView though, the onClick method is called.
If I specify the onClick of the EditText it works. I am wondering why though it doesn't work through the root ViewGroup's onClick.
I have tried many different things like
Disable/Enable the EditText using inputType
If EditText is non-editable and clickable set focusable to false and clickable to true
Disable/Enable EditText using enabled true/false
It's really weird because the EditText is actually almost the same as the TextView that behaves as expected.
Any ideas?
try to change this
android:clickable="#{!viewModel.isEditTextClickable}"/>
for
android:clickable="#{viewModel.isEditTextClickable}"/>

AppCompatEditText focus Issue

I have long form (LinearLayout as root) which consist of EditTexts and TextView.
Now Issue i am facing is : After clicking the Edit Text, if i clicking on textviews then the focus of an edit text is not clearing. Hence, screen scroll to that edit text due to focus.
I have tried solution - android:focusableInTouchMode="true" in parent layout but no luck.
I have attached an image showing an issue. I have clicked on consulting doctor field which is a TextView but focus is till on email Edit text.
Please help me with some solution. Thanks.
After clicking the Edit Text, if i clicking on textviews then the focus of an edit text is not clearing. Hence, screen scroll to that edit text due to focus.
Wrap your EditText inside FrameLayout as shown below
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
public static void hideSoftKeyboard (View view)
{
InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}
//Call this method on textview click

Android: Prevent focus from jumping when hiding view

I have an Android activity that contains multiple EditText views.
If I programmatically hide the currently focused EditText, then the focus will automatically jump to the next EditText.
Is there anyway to disable this behavior so that the focus is cleared when the EditText is hidden rather than automatically jumping to the next EditText?
Thanks.
You need to provide Focus to a parent view above your EditText just like the sample code below
<RelativeLayout
android:id="#+id/search_edit_text_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true" >
<EditText...
Do try this to avoid providing focus directly to the next EditText

Android Show/Hide Widget Resize Fill Parent

I have an EditText with a Button next to it. The button is hidden at first so the EditText takes up the full screen, which is good. When they tap the EditText I have the button appear next to the EditText, and it resizes itself accordingly. However, when I hide the Button (I set visibility to gone), the EditText does NOT resize to full screen (leaving a gap to the right of the EditText). Any tips?
I have tried putting the EditText and Button in both a LinearLayout and a TableLayout (with stretchable column, etc) and I see the same behavior. I also tried doing some runtime calls to removeView/addView stuff and that didnt work. I also tried calling invalidate() on both the EditText and its parent.
Thanks!
I encountered the same question, I want to change the size of an EditText when hiding and showing a Button which stands next to it, but the EditText's size will not shrink after call setVisibility(View.VISIBLE) on the button. I solved it by adding a android:layout_weight="1" to the EditText.
The layout xml looks like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/search_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<Button
android:id="#+id/hide_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn"
/>
</LinearLayout>

Categories

Resources