In my form I have different EditText areas and a Button on the end.
If I use android:nextFocusForward and android:nextFocusDown between EditText in my XML file everything is ok, but if I use these in the last EditText in order to give focus to the Button I get:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{org.test/org.test.myActivity}: java.lang.ClassCastException:android.widget.TextView
I even tried:
android:focusableInTouchMode="true"
Of course they are in the same GroupView.
Can you try if this works, of course this is a code solution not an xml one:
button.requestFocus()
Related
I have an EditText in my Android app. When I write something on it I don´t have the enter on my Keyboard and when the cursor goes to the final of the line doesn´t jump to the line below automatically. Which are the properties to change this? Thank you so much.
I answer my own question, it works
edittxt.setInputType(EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
edittxt.setMinLines(minLines);
edittxt.setGravity(Gravity.TOP);
edittxt.setVerticalScrollBarEnabled(true);
edittxt.setSingleLine(false);
Write these two lines in edit text xml
android:singleLine="false"
android:inputType="textMultiLine|textAutoCorrect"
I have two edit text fields on my phone:
'Name:' and 'Phone:'
Whenever I launch my program, my cursor is already in the 'phone' field with the number keyboard pulled up. However, I'd like for it to center on the first editText, 'name', so that the regular keyboard pulls up.
Does anybody know why this is working this way, and how to correct it?
(EditText)txtName = findViewById(R.id.NAME_ID);
txtName.requestFocus();
Do this in your onCreate() after you've inflated your layout
See requestFocus tag on your layout
You can do this in code with a requestFocus() method on the view:
https://developer.android.com/reference/android/view/View.html#requestFocus()
or with an tag inside the view tag in the layout:
https://developer.android.com/guide/topics/resources/layout-resource.html#requestfocus-element
I have four edittexts the problem is when i start activity the focus will be on the last edittext , how can i make the focus on the first edittext using xml ?
Thanks
onCreate(); of Activity
EditText firsteditText=(EditText)findViewById(R.id.first);
EditText secondeditText=(EditText)findViewById(R.id.second);
EditText thirdeditText=(EditText)findViewById(R.id.third);
EditText fourtheditText=(EditText)findViewById(R.id.fourth);
firsteditText.requestFocus();
You can use the requestFocus element.
You can also add a <requestFocus/> tab in the activity xml.
In Android Studio 2.3.3, you can click on the focusedByDefault attribute in the Properties panel on the EditText you want the focus on first.
I have an edittext for reply to email. i want to give three properties for edittext like Multiline, First character caps and disable word suggestions.
I gave like this in xml...
android:inputType="textCapSentences|textVisiblePassword"
I tried in code also... etMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
I am not able to give multiline....how can i achieve this
thanks
I found solution for this problem
Just set the following parameters in xml file..
android:inputType="textCapSentences|textVisiblePassword"
These are for setting first letter of sentence to caps and disable suggestions
and write following code in ur Activity
edittext.setSingleLine(false);
Try setting android:inputType="textMultiLine|textCapSentences|textVisiblePassword". What might be happening is that it is multiline but only one line is currently shown, in which you could say android:minLines="5" or so.
I have an edit text and I'd like to put the following constrains (in the XML code if possible):
Disable all the capital Letters (the inverse of android:capitalize or the same fonction than toLowerCase())
Block to EditText to 1 line max. (for instance avoid that when I press enter the editText
get bigger to create a new line)
In fact , my editText is a Search Field (but in my case I don't want to use the special Search Widget).
Thanks
To make the edittext single line add this to its tag:
android:singleLine="true"
Also android:capitalize is depreciated and the following should be used instead
android:inputType="textCapCharacters"
However there seems to be no matching lowercase inputType, so you may have to implement it manually using a setOnKeyListener.
use android:lines="1" in the android xml page and then see the layout.