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}"/>
Related
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
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
Expected Result
There is a search bar implemented using a EditText inside a RelativeLayout. For some reason, the query to be searched is not going to be inputted into the EditText direct, but instead, on clicking the search bar, a WebView is triggered and load a search page where the user can input their search query there.
Problem
Set android:onClick="selectCellSearch" to RelativeLayout, click on the EditText the selectCellSearch callback function given by onClick seems not to be triggered.
Source Code
layout.xml
<!-- Start of Search Bar Cell -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="87dp"
android:background="#212121"
android:clickable="true"
android:onClick="selectCellSearch"
android:tag="search" >
<EditText
android:id="#+id/edit_text_search_id"
android:layout_width="fill_parent"
android:layout_height="85dp"
android:layout_marginBottom="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="1dp"
android:hint="#string/edit_text_search_id"
android:textSize="28sp"
android:textStyle="normal"
android:enabled="false"
android:inputType="none" />
</RelativeLayout>
<!-- End of Search Bar Cell -->
Notes
The android:tag="search" is used for the URL generation of the search page to be loaded after clicking on the search bar, say, http://mywebsite.com/search.
Update
The selectCellSearch() is now posted here.
MainActivity.java
public void selectCellSearch(View view) {
final String tag = (String) view.getTag();
if (tag != null) {
buttonForWebViewSlideInAnimation.performClick();
mWebView.loadUrl(WEB_BASE_URI + tag);
}
}
First of all, it's not advisable use the xml attribute onClick to set the onClickListener. Use the setOnClickListener method to do that always.
Second, the EditTest occupy all the size of the relative layout and is "over the relative". This situation produces that the onClick of the RelativeLayout never called.
To receive the click you can:
Are you sure that the RelativeLayout is totally neccesary?
You can set the onClick on the EditText
Override the onInterceptTouchEvent or dispatchTouchEvent on your RelativeLayout. This methods will received the touch events (all, care about this!)
Try android:duplicateParentState="true" in EditText
I am developing an android application.
I was created an activty that contains several components
on the top it contains spinner,
after that it contains linear layout in which it has two textview,
1 has static value and other is dynamic value that is filled when user click on that linear loyout an dialogbox is created and after setting value on that dialog it fills other textview.
i have 4 linearlayout of this type after that i have another linear layout at the end that contains 2 button.
The problem is that in emulator when i scroll mouse it focus on the spinner and after that the last button(means it color changes to orange)
So the question is that how can i get focus on that 4 linear layout?(i set focusable & focusontouch & clickable value true of that linearlayout.)
I have done this, and setting android:clickable="true" on my LinearLayout did the trick. I just set a click handler for that layout when I set up my views.
From #david-lord's comment, only the parameter
focusableInTouchMode="true"
is necessary, so in XML
<LinearLayout
android:id="#+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusableInTouchMode="true">
allows the call
linear_layout.requestFocus()
I have a LinearLayout with:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selectorbarbutton"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
and this work getting focus and click events correctly.
Please try to set android:focusable=true ,
I am not sure about this but may solve your problem.
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>