EditText is not editable in Fragment - android

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.

Related

Can you add a textview or something similar as a child to a textinputlayout?

I have an application that uses a lot of textinputlayouts because I like the style they create
on one screen I am showing info on one object and I want it too look like the data the user entered with the textinputedittexts , small caption above and the data below
right now I have a textinputlayout with a disabled textinputedittext below
is there a way to just have a textview under the textinputlayout that will be shown in the same style?
thanks in advance for any help you can provide
edit:
as a side note here's what I am currently using to disable the edittext fully
<android.support.design.widget.TextInputLayout
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/name"
tools:text="This is where the name goes"
android:inputType="none"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" />
what I am trying to avoid is not use clickable and inputtype etc etc in EVERY view that I'm trying to create, and instead use a single view
so other than creating a custom edittext (like NeverEnabledEditText) that starts unclickabke in every way, or add all those attributes to my xml, is there a way to do the above?
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/date_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Date"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/tv_date"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="none"
android:clickable="true"
android:focusable="false"
android:drawableEnd="#drawable/ic_keyboard_arrow_down_black_24dp"
android:paddingEnd="4dp"
android:paddingVertical="12dp"
android:drawablePadding="4dp"
android:textColor="#color/colorPrimary"
tools:text="00/00/0000" />
</com.google.android.material.textfield.TextInputLayout>
Although a TextInputEditText, now you have it acting like a textview because you can't edit it but can set text to it. You're welcome !

TextView singleLine

I want to create a textview with a single line which is inside a swipelayout. Every textview represents an action on which the user can touch. All textviews have a width of 100dp. Now i have the problem that the text of a textview is too long and it wraps to the next line. I don't want to use android:singleLine="true". Now i added android:maxLines="1" and android:inputType="text" and it works fine. But now i get the warning:
Attribute android:inputtype should not be used with <TextView>: Change
element type to <EditText>
I don't want to enter text so i don't need an EditText.
Is there another way or should i just ignore this warning?
<TextView
android:id="#+id/item_list_bottom_rename"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text"
android:layout_gravity="center"
android:drawableTop="#drawable/ic_visibility_white_36dp"
android:gravity="center"
android:padding="10dp"
android:text="#string/rename"
android:textColor="#color/item_title_listname"/>
Solution:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true"
android:minWidth="100dp"
android:scrollbars="none">
<TextView
android:id="#+id/item_list_bottom_rename"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableTop="#drawable/ic_visibility_white_36dp"
android:gravity="center"
android:maxLines="1"
android:text="#string/rename"
android:textColor="#color/item_title_listname"/>
</HorizontalScrollView>
Have you read what it says ?
Using a <TextView> to input text is generally an error, you should be
using <EditText> instead. EditText is a subclass of TextView, and some
of the editing support is provided by TextView, so it's possible to
set some input-related properties on a TextView. However, using a
TextView along with input attributes is usually a cut & paste error.
To input text you should be using <EditText>.
InputType -Bit definitions for an integer defining the basic content type of text held in an Editable object. Supported classes may be combined with variations and flags to indicate desired behaviors.
Attribute android:editable should not be used with <TextView> and thats the reason!
you can remove that inputType in your textView
without android:singleLine="true" but with android:maxLines="1"
Alternatives
1.use what compiler asks :P EditText and make it act as textView
<EditText
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:inputType="text"
android:maxLines="1"
android:text="Helloo"
android:id="#+id/Id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent" >
</EditText>
2.you can also use
<HorizontalScrollView
android:fillViewport="true"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/item_list_bottom_rename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxLines="1"
android:text="Heloo" />
</HorizontalScrollView>

How to make Edit Text hint appear when typing

I would like for my app to be able to display different hints in the edittext at different times, so i have to set the hint pro-grammatically at each times as below.
editText.setHint("Hint 1");
But the problem is when i starts typing the hint starts disappearing.I want to show this hint every time.If i set the hint in xml it will not disappear while typing, but how to do this in my case.
Either you should consider to change to TextInputLayout(Strongly recommended this. Here is an example too.)
or
make relative layout with EditText for input and TextView for hint inside.Change the textview according to your needs.
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text"
android:layout_alignParentLeft="true"
android:id="#+id/editText1"
android:layout_gravity="center"
/>
<TextView
android:id="#+id/text_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="yourHint"
android:textSize="14sp"
android:layout_marginRight="10dp"
android:textColor="#color/customColor"
/>
</RelativeLayout>
what you are expecting is not possible,since we have to how what user is writing on editext.
Now a days https://github.com/hardik-trivedi/FloatingLabel
this type of hints are more popular,you can try above link.
TextInputLayout give powerful material features to EditText. Main feature is floating hint. See doc here https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html
You can't display while typing text in edit text hint in android have default functionality
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel"
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/username_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="Email Address"
android:inputType="textEmailAddress"
android:translationY="10dp"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_13"/>
</android.support.design.widget.TextInputLayout>
Here android provide default functionality while typing text in edit text the hint above edit text, You can also set Hint via programmatically
EditText. setHint ("Hint 1");
the best way to do this is to use TextInputLayout.
https://www.bignerdranch.com/blog/becoming-material-with-android-design-support-library/
<!--EMAIL-->
<android.support.design.widget.TextInputLayout
android:id="#+id/email_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextLabel">
<EditText
android:id="#+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/login_screen_email_hint"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"
android:nextFocusDown="#+id/etPassword"
android:singleLine="true"
android:textColor="#android:color/white"
android:textColorHighlight="#android:color/white"
android:textColorHint="#android:color/white" />
</android.support.design.widget.TextInputLayout>
And dont forget adding this line to your gradle file
compile 'com.android.support:design:23.4.0'

EditText won't write into single line

I'm making a calculator and user input is contained in EditText. Input is typed through buttons on screen, so Android keyboard is disabled. However, I want it to write all input in one line and when line reaches border, it needs to be ellipsized and then horizontally scrollable so you can reach whole text.
I tried doing this by setting android:maxLines="1" and android:ellipsize="end", but that doesn't work. Text is still in multiple lines, but only one line is visible and you need to scroll vertically to see other lines. I also tried using android:singleLine="true", but that makes EditText completely unusable.
This is EditText XML:
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp" />
I think this will work for you. Let me know if it works.
<EditText
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#color/colorBlue"
android:textAlignment="textEnd"
android:textSize="40sp"
android:inputType="text"
android:maxLines="1"
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"/>
This post might help you as well.
For single line in EditText, you just need to set two properties:
android:inputType="text"
android:maxLines="1"
Adding this line in the edittext make scrollable singleline text.
android:inputType="textShortMessage"
**This example helps you to create multiline EditText in Android.**
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context=".MainActivity"
>
<!--
android:scrollbars="vertical"
It will display a vertical scrollbar if the EditText text exceed
3 lines (android:maxLines).
-->
<EditText
android:id="#+id/et"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:hint="Multiline EditText by XML layout"
android:fontFamily="sans-serif-condensed"
android:background="#d3d7b6"
android:minLines="2"
android:maxLines="3"
android:scrollbars="vertical"
android:inputType="textMultiLine"
/>
<EditText
android:id="#+id/et2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="sans-serif-condensed"
android:hint="Multiline EditText programmatically"
android:background="#d4d7a5"
android:layout_below="#+id/et"
/>
</RelativeLayout>

Can't focus EditText

I have a simple EditText inside my scrollview.
All the other elements are working just fine, however i won't get the usual EditText behaviour on click (Keyboard doesn't appear, I can't write).
Here's my xml for the field.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/enterWishprice"
android:background="#drawable/edit_back"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="0 F€"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp"
android:inputType="number"
android:layout_margin="10dp" />
As you can see I already tried setting focusable/inTouchMode.
I also tried setting a click listener on the field to manually open the keyboard which works just fine. However I still can't type anything into the field.
After that i tried using requestFocus in the clicklistener without any result.
Furthermore I tried clearFocus on the EditText as well as the surrounding ScrollView - also not working.
Hopefully you can give me a hint cause I'm out of ideas..
Thanks in advance!
The attribute Enabled must be set to true.
<EditText
android:id="#+id/room_message"
android:layout_width="164dp"
android:layout_height="46dp"
android:clickable="true"
android:ems="10"
android:enabled="true"
android:focusableInTouchMode="true"
android:hint="#string/prompt_message"
android:inputType="textPersonName"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="italic"
/>
But i have got another problem where the EditText won't lose focus....
try like this
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/enterWishprice"
android:background="#drawable/edit_back"
android:focusableInTouchMode="true"
android:text="0 F€"
android:gravity="center_vertical|center_horizontal"
android:textSize="26dp"
android:inputType="number"
android:layout_margin="10dp">
<requestFocus />
</EditText>

Categories

Resources