In my RecyclerrView some items have EditText(Inside cardView).It works fine without defining InputType in EditText but when I define InputType it causes the recyclerview to scroll to position zero when EditText comes into focus(When touched on editText to enter values).
This is a default EditText that works fine
<EditText
android:id="#+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp_5"
android:layout_weight="1"
android:background="#drawable/box_blue_outline"
android:gravity="center"
android:hint="#string/name"
android:padding="#dimen/dp_5"
android:textSize="#dimen/sp_16" />
I have another EditText that accepts numbers only so I added InputType
<EditText
android:id="#+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/dp_5"
android:layout_weight="1"
android:background="#drawable/box_blue_outline"
android:gravity="center"
android:inputType="number"
android:hint="#string/number"
android:padding="#dimen/dp_5"
android:textSize="#dimen/sp_16" />
But clicking on this EditText to enter values, which has some position between the RecyclerView (say 7), it scrolls back to position 1.
Look like, different keyboard changes cause RecyclerView to update. It's very possible of the Window focus type. Try to change Keyboard behavior for appearing in Activity/Fragment onCreate.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Please include all View layouts, where located RecyclerView and what layouts you are binding.
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 don't know why is this happening.. In other activities EditText is working fine. This is how my fragment layout looks:
<EditText
android:gravity="center"
android:inputType="text"
android:background="#android:color/transparent"
android:layout_below="#+id/profile_image"
android:text="Dusan Dimitrijevic"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:textColor="#android:color/black"
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Is something affecting in layout these EditTexts so they can't be editable. If i need to show you Java code, let me know. I can set text to EditText by the way, but can't edit it..
Remove the background and the text. Use hint instead of text
<EditText
android:gravity="center"
android:inputType="text"
android:hint="Dusan Dimitrijevic"
android:layout_below="#+id/profile_image"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:layout_marginTop="20dp"
android:textColor="#android:color/black"
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
I encountered this and resolved by identifying an overlapping layout/element declared below editText thus preventing interaction with the editText element. My editText element envelop (parent) layout had the same:
android:layout_below="#+id/xxxxxx"
specification as the layout below it.
I am making an Android app and want the done key to show up on the keyboard when the user is typing into the keyboard.
This is the XML code for the EditText:
<EditText
android:id="#+id/answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:layout_marginBottom="113dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:imeOptions="actionDone"
/>
I thought that adding the android:imeOptions="actionsDone would have the done button appear, but instead the enter button is there and when it is pressed, a new line is created in the EditText. What is the issue?
You will not get done by adding imeOptions.
Add the below attribute to your EditText:
android:singleLine="true"
This will make your EditText a single line and you will see the Done button if that is the only EditText or last EditText. If there are multiple EditText items, then you will see Next button.
I have an EditText and have a hint. When I tap on the EditText, the keyboard appears, though, as I type neither the hint goes away nor my typing goes into view. It's like my input is going to /dev/null. My EditText is inside a ListView cell, if it helps. Here is my layout:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#00000000"
android:id="#+id/aboutView"
android:layout_gravity="center_horizontal|bottom"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headerFrame"
android:layout_marginTop="12dp"
android:gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textSize="14dp"
android:layout_marginBottom="12dp"
android:hint="Tell something about yourself..." />
Why can this be?
Found the solution here: EditText in Listview loses focus when pressed on Android 4.x
I don't know the exact reason, but I wasn't the only one suffering from EditText focus problems when inside a ListView. I've added android:windowSoftInputMode="adjustPan" to my activity in manifest file and the problem went away.
I have an EditText defined in my half screen RelativeLayout. and it appears perfectly. However, if I start typing typing more than 1 line in my EditText, it makes my entire entire window expand. I want the EditText to roll up and only show the currently typing line? Like in Facebook Messager, I want the EditText to keep scrolling itself as the user types new lines? HEre is how I implemented the EditText
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/button1"
android:ems="10"
android:focusable="true"
android:inputType="textMultiLine" />
Just set
android:maxLines="1"
This makes the TextView be at most this many lines tall.