I have a ListView with EditText in each row. So I cannot type anything in any EditText as well as not focus when tap on them.
Xml souce:
<EditText
android:id="#+id/textValue"
android:layout_width="match_parent"
android:layout_height="37dip"
android:editable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="left|center"
android:inputType="text">
</EditText>
Thanks in advance.
If you want to be able to focus on the EditTexts, remove the lines that set it as non-editable:
android:focusable="false"
android:focusableInTouchMode="false"
Use TableLayout instead of ListView because EditText has focusable problems in ListView.
you made the EditText unfocusable with those two lines:
android:focusable="false"
android:focusableInTouchMode="false"
just remove or set the value to "true" in order to use them
Related
I have a ListView look like the following, and each entry consists of two normal TextViews and one toggle button.
I want to add a floating hint and a word counter for the TextViews on each entry. So, I changed the TextView to TextInputEditText, and they look like the following:
The problem is after I use TextInputEditText, the onItemClickListener no longer responds to clicks. I tried different settings for android:descendantFocusability="blocksDescendants" on the list entry, and also tried android:focusable="false" and android:focusableInTouchMode="false" on the TextInputEditText.
What settings do I need to make TextInputEditText completely disabled/un-editable like a regular TextView while keeping its nice floating hint and word counter?
Code for normal TextView, which works well with onItemClickListener
<TextView
style="#style/bodyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/thin_boarder"
android:text="TestName 1"/>
code for TextInputEditText which does NOT work with onItemClickListener
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="top|start" />
</com.google.android.material.textfield.TextInputLayout>
I have an EditText that is wrapped in a TextInputLayout that is inside a LinearLayout and I want to show a fragment when the LinearLayout is touched. However the EditText is intercepting the touch.
I tried setting focusable="false" and clickable="false" on the EditText and the TextInputLayout but now the touch doesn't do anything except change the hint color slightly for a little bit.
I don't want to set enabled="false" because of the grayed out style color changes.
My xml:
<LinearLayout
android:id="#+id/type_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:id="#+id/type_input_layout"
android:clickable="false"
android:focusable="false">
<EditText
android:id="#+id/type_input"
android:hint="Type"
android:text="Public"
android:clickable="false"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|textMultiLine"
android:background="#color/transparent"
android:gravity="left"
android:textSize="22sp"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
My solution for now: just put a view on top of the edittext
try this ,may be its working
set in your linear layout
android:clickable="true"
set in your editText
android:clickable="false"
android:focusable="false"
remove from TextInputlayout this 2 lines
android:clickable="false"
android:focusable="false"
Try android:enabled="false". I'm not sure but it might work.
Try using android:descendantFocusability="blocksDescendants" on your LinearLayout to make children view not focusable.
You can also try using both focusable properties
android:focusable="false"
android:focusableInTouchMode="false"
EDIT:
Try android:duplicateParentState="true" for every child view of the LinearLayout. You can also look at this question. There is someone mentioning that inputType on EditText can intercept the click.
In xml for EditText you should declare:
android:clickable="false"
android:longClickable="false"
This will make it not able to take over the click.
I know that is possible to disable editing EditText.
Answers is here, and here.
But, when i disable EditText it also disabled vertical scroll in this text.
Is it possible to disable only editing, but allow scrolling?
editText.setFocusableInTouchMode(false);
editText.clearFocus();
Use this porperties in your EdittText:
android:enabled="true"
android:focusableInTouchMode="false"
android:scrollbars="vertical"
Your EditText will be enable, but not focusable for edit. Then, you will able to scroll (in vertical on this case) and will not able to edit.
I've found that just disabling the key listener, focusable and cursor seems to work:
editText.setKeyListener( null );
editText.setFocusable( false );
editText.setCursorVisible(false);
As long as you keep the edit text enabled you seem to be able to scroll the text still.
If you wrap your EditText in a ScrollView then you should be able to preserve the scroll behavior.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText ... />
</ScrollView>
editText.setKeyListener(null) should help you.
Try to use these two attributes to your editext it will make your editext only scrollable not editable
android:inputType="none"
android:textIsSelectable="true"
Below is the example
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"
android:padding="20dp"
android:layout_margin="10dp"
android:textSize="#dimen/text_size"
android:inputType="none"
android:textIsSelectable="true"
android:textStyle="normal"
android:id="#+id/toeditext"
android:textColor="#android:color/white"
/>
I got a ListView contains an ImageView and an EditText for each row. Both of them are non-clickable, but the onItemClick only work on ImageView, but not the EditText. Please help.
The following is the row of ListView:
<ImageView
android:id="#+id/img_item_info"
android:cursorVisible="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="#dimen/icon_32"
android:layout_height="#dimen/icon_32" />
<EditText
android:id="#+id/edt_browser_item"
android:singleLine="true"
android:background="#drawable/browser_textview_style"
android:layout_marginLeft="#dimen/margin_between_image_textview"
android:inputType="none"
android:scrollHorizontally="true"
android:cursorVisible="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
Best regards,
Antony
android:focusable="true"
android:focusableInTouchMode="true"
on both of the views (Imageview and edittext)
Now you can able to select the imageview and edit the edittext.
Why do you use EditText and trying to block it? Just use TextView if you want to get unclickable EditText.
I have an input box - edittext in android, which is not single line. I want that when three lines are complete then the edittext should stop expanding and scrollview should attach to the edittext at that time.
I can add scrollview directly?
try like this way
<EditText
android:id="#+id/users_first_name"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:hint="First"
android:focusable="true"
android:inputType="textPersonName"
android:enabled="true"
android:maxLines="3"
>
</EditText>
use android:maxLines="3" for your EditText tag in xml.