Why won't my EditText element accept any input on Android? - android

Here's the code for my EditText element:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text=""
android:id="#+id/myTextEdit"/>
The entire app builds and I'm not using this element in code yet, but when it shows up on the screen I cannot type into the element.
This EditText element will not accept text any time I try to type into it.
Do you know why?

The entire reason it fails is because the EditText element is already selectable.
For some reason adding the following property causes the element to be uneditable:
android:textIsSelectable="true"
I removed the property from the layout and I could type text into the element.

Related

How to expand textfield after a line of words

My textfield not expanding after line of words. I can't see my first line after write second line for text box. I want to expand automatically text field. My text field not creating new line after writing words. I can send my message but can't see another lines before send. My language is kotlin.
just use:
<TextView
android:id="#+id/textView"
android:layout_width="150dp"
android:layout_height="wrap_content"/>
Define input type in text field element .
android:inputType="textMultiLine" and layout height android:layout_height="wrap_content"
Still not solved then please attach your layout XML file.
If you want your textview to become flexible, you shouldn't give to it fixed size of
height.
Make its height "wrap_content" so textview's size will change according
to what you write inside it.
Just add:
android:layout_height="wrap_content"

EditText added is not a TextInputEditText. Please switch to using that class instead

I'm using an EditText inside a TextInputLayout, but after upgrading the support library to 23.2.0, I get this warning in the logcat, What's the difference between a regular EditText and a TextInputEditText? I can't seem to find any documentation for it.
I was wondering this too, Daniel Wilson gathered the documentation, but to the untrained eye it doesn't mean much. Here's what it's all about: "extract mode" is referring to the type of view that's shown when the space is too small, for example landscape on a phone. I'm using Galaxy S4 with Google Keyboard as input method editor (IME).
Landscape UI without visible IME
Based on the focus (on Description) you can see TextInputLayout in action pushing the hint outside the editor. Nothing special here, this is what TextInputLayout is supposed to do.
Landscape UI editing empty Name field
Editing the Name you can see that the IME doesn't give you a hint of what you're editing.
Landscape UI editing empty Description field
Editing the Description you can see that the IME gives you a hint of what you're editing.
Layout XMLs
The difference between the two fields is their type EditText VS TextInputEditText. The important thing here is that TextInputLayout has the android:hint and not the wrapped EditText, this is the case when TextInputEditText's few lines of Java code makes a big difference.
Name field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Name"
>
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
Description field
<android.support.design.widget.TextInputLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Item Description"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="4"
android:scrollbars="vertical"
/>
</android.support.design.widget.TextInputLayout>
There is no documentation for it, but the class is a regular EditText with a single extra feature:
Using this class allows us to display a hint in the IME when in 'extract' mode.
Specifically it sets the EditorInfo.hintText. You'll notice in the TextInputLayout class you can specify the hint and it's appearance rather than as part of the child EditText widget.
If you need to do that, you should use a TextInputEditText so it pays attention to the hint info you specified in the TextInputLayout.
They are essentially the same thing, but I think the TextInputEditText has more features and possibly attributes. I changed to the TextInputEditText and everything worked and looked as it did before with the standard EditText.
The only difference is that when your device is in landscape mode, TextInputEditText will show the hint, EditText won't.
I had this problem and just deleted this line in my xml file:
android: fitsSystemWindows = "true"
and the error disappeared.

TYPE_CLASS_NUMBER input type on android scrolls ScrollView to it's right end. Why?

I have a HorizontalScrollView, in which I have an EditText. If I don't set any input type, it works just as expected. However, if I use TYPE_CLASS_NUMBER, it scrolls to the right end when I select it. Why? How to fix this problem?
Text input has a left gravity/justification and number input has a right gravity/justification.
You can override this either in your layout xml or programmatically.
<EditText
android:id="#+id/etNumbers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:inputType="number"
android:hint="#string/et_number_hint"/>
or
EditText etNnumber = (EditText) findViewById(R.id.etNumbers);
etNumber.setInputType(InputType.TYPE_CLASS_NUMBER);
etNumber.setGravity(Gravity.LEFT);
Post your existing implementation and I can edit this with an actual code solution.

EditText not using its attributes in XML

<EditText
android:id="#+id/drawer_search"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:background="#color/white"
android:drawableLeft="#android:drawable/ic_menu_search"
android:hint="#string/drawer_search_hint"
android:imeOptions="actionSearch"
android:maxLines="1"
android:textColor="#color/dark_blue"
android:textColorHint="#color/dark_blue"
/>
So... all of the attributes work except imeOptions and maxlines. I want the text view to be only one line and the keyboard to not have a return key to go to the next line. It needs to submit/search what ever is in the text view.
So this is the text view. cropped for space.
If you press enter/return it goes to the next line(which there should only be one line).
Why isn't the textview using all of the attributes?
Is there a better way to make it so the keyboard's return button is a submit button rather than next line?
The layout file is declared like this.
View headerRoot = inflater.inflate(R.layout.drawer_header, null);
Attribute android:maxLines corresponds to the maximum height of the EditText or TextView. Use android:singleLine=true for one line input.

This text field does not specify an inputType or a hint

I get the warning, "This text field does not specify an inputType or a hint" When I modify a copy of a tutorial code (below)
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:layout_weight="1" />
This works fine, and the warning only comes up if a new blank line is created
I've modified it for a friend with several comments lines explaining what each part of it does however, whenever i add in an extra line in the above (Even a blank line, in this case it's a comment line) I receive the above error
<!--edit text creates a text input box-->
<EditText android:id="#+id/edit_message"
<!-- edit_message is a variable, defined in strings.xml-->
<!-- determines the width of the textField, in this case 0dp means "however long the text is" IE: it will grow to fit however many characters the user types -->
android:layout_width="0dp"
<!-- determines the height of the Text Field -->
android:layout_height="wrap_content"
<!-- The hint is the default value for the text field, it calls on the variable edit_message defined in strings.xml-->
android:hint="#string/edit_message"
<!-- Weight means how much the screen the text field can take up, in this case, the ratio is 1:1 so it can take up however much room is needed, However if a different variable also had the weight of 1, the ratio would be 1:2 and each could take up half the screen -->
android:layout_weight="1" />
Without the comments, the warning is not there
The Reason for this warning is that you haven't set the inputType for this editText. Add the following line:
android:inputType="text"
So it should look like this:
<EditText android:id="#+id/edit_message"
android:inputType="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/edit_message"
android:layout_weight="1" />
And the warning is gone.
Logically you should get warning in the line
<EditText android:id="#+id/edit_message"
and an error in the next line.
Reason:
When you are placing comment tags, then the closing tag of comment is considered as the illegal closing tag for EditText. So you should even get the following error
Element type "EditText" must be followed by either attribute specifications, ">" or "/>".
and because of the above error the remaining code is not executed and thus you get a warning
This text field does not specify an inputType or a hint
even though android:hint attribute exists in your code.
I just run your code and got my app running properly, when i added the comment it crashes, then i realized that you should not comment inside your XML , it is a principle of XML.
I suggest you to read this article explaning what is a well formed XML and how to comment xml in the right way http://webdesign.about.com/cs/xmlinformation/ht/htcommentxml.htm
Also here has been a discussion about this particularly subject and has been solved as well.
https://stackoverflow.com/a/2073162/2069737
Hope it helps you.

Categories

Resources