Android Edittext looses focus while typing in the keypad - android

I have one Edittext and there is a listview below of that edittext.Initailly Listview visibility set to GONE. Once user is typing in the edittext then I am making listview to Visible by populating refined results in the listview. But here after typing one letter in edittext, the edittext looses its focus. Again user needs to click on edittext and have to type to proceed. My question is how to make edittext not loosing focus when listview gets its visibity. Any help greatly appreciated.

just give in xml editext:
<EditText
android:id="#+id/editText1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textShortMessage" >
<requestFocus />
</EditText>

Set
edittext.requestFocus();
in the place where u are setting the listView visible..

Related

Numeric edittext loses focus after first input in listview

I have multiple edittexts in my listview, numeric and normal. When I click on a numeric it gets the focus and pops up the keypad but after I enter 1 number, it loses its focus and I have to click on it again to enter more numbers. Is there a way to keep focus so I can enter more numbers? My normal edittext works perfectly.
I have already tried with adjustpan and different keyboard modes.
edittext code:
<EditText
android:id="#+id/etEditTextItem"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_alignParentRight="true" />
Listview code:
<ExpandableListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/colorCard"
android:groupIndicator="#null">
</ExpandableListView>
The problem is the listview : you have to add the following to manifest in the listview activity
android:windowSoftInputMode="adjustPan"
and the following to listview
android:descendantFocusability="beforeDescendants"
I managed to fix it, after debugging the currentFocus i found out that the listview onExpand() took the focus away, setting editText.requestfocus() after returned the focus to the edittext.
I have the same issue, but my EditText is not in any ListView. It is simply inside several nested LinearLayouts and also looses its focus as for . What fixed my issue was to add TextChangedListener for this EditText in activity code and in onTextChanged I set:
EditText.requestFocusFromTouch()

Android multiline EditText

I've one EditText with multi-lines.
The problem is that, while I am adding more and more lines, just pressing ENTER or typing, the EditText keeps scrolling down which is OK, but after approx. 10 lines whole activity is scrolling.
And when I click again on EditText, the opened keyboard covers whole EditText.
But, when I click only on 3rd line, keyboard isn't covering EditText and View is moved like it should have.
Any advice please?
Okay,Using EditText in ScrollView Like this way
<ScrollView
android:layout_height="100dp"
android:layout_width="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#54D66A"
android:textSize="17sp" />
</ScrollView>
For programmatic approach please check
http://developer.android.com/reference/android/text/method/ScrollingMovementMethod.html
You can give android:maxHeight="60dp" to your EditText to stop scrolling of the whole Activity and it will solve other problem also.
I hope it helps.

How to keep cursor from going to editText field on activity start android

I am having a problem with text edits. I suppressed the keyboard from poping up on activity start, but how do I keep the cursor from being on the first edit text? I want the cursor to appear only when the editText field is clicked and when the activity starts.
<EditText
android:id="#+id/stuff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/stufflabel"
android:layout_toRightOf="#+id/stuffpic"
android:hint="#string/name_str"
android:maxLength="20"
/>
Kindly search the forum for similar posts.
one post i found is -
Android: Force EditText to remove focus?
I hope you are looking for something similar !
enjoy :)
You can add a dummy EditText on inside layout of the XML file, so that the focus will get on that EditText and not on other EditText.
<EditText
android:layout_width="0dp"
android:layout_height="0dp" />

Scroll horizontal in disabled edittext

An edittext turn enabled or disabled in code (if "EDIT" button is pressed or not).
The problem is: if edittext contains a large text and his status is disabled, i can't scroll horizontal for view all text. (if his status is enabled, i can scroll horizontally normally)
if you wrap your EditText in HorizontalScrollView the user can scroll it horizontally even if EditText is disabled :
<HorizontalScrollview
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
You can use the following parameters in the edittext.
edittext.setFocusable(false);
edittext.setClickable(false);
edittext.setFocusableInTouchMode(false);
edittext.setEnabled(true);
edittext.setKeyListener(null);
edittext.setHorizontallyScrolling(true);
So it will work as the desired behaviour.
This is my Edittext in XML
<EditText
android:id="#+id/et_myEdtitText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxLines="1"
/>
and in JAVA add this,
et_myEdtitText.setKeyListener(null);
Now i won't be able to add any text in Edittext. Because, i have disabled KeyListener, But i will be able to scroll your Edittext horizontally

Added text in EditText hosted by ListView row is removed upon keyboard closing

I use following GUI setup:
ListView activity
CursorAdapter that feeds this list
Layout for activity
Layout for rows in ListView :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity = "right" >
<TextView android:id="#+id/text_9_description_top"
android:layout_width="wrap_content"
android:layout_height="fill_parent" android:gravity="right|center_vertical"
android:layout_alignParentLeft="true">
</TextView>
<CheckBox android:id="#+id/chkApprovedTabChapter9"
android:layout_toRightOf="#+id/text_9_description_top"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:gravity="right" >
</CheckBox>
<Button android:id="#+id/tabchaprter9_row_button_delete"
android:layout_height="wrap_content" android:text="leftBtn"
android:layout_width="wrap_content" android:background="#android:drawable/ic_menu_delete"
android:layout_toRightOf="#+id/chkApprovedTabChapter9" >
</Button>
<Button android:id="#+id/tabchaprter9_row_button_edit"
android:layout_width="wrap_content" android:layout_toRightOf="#+id/tabchaprter9_row_button_delete"
android:text="rightBtn" android:layout_height="match_parent"
android:background="#android:drawable/ic_menu_edit">
</Button>
<EditText android:layout_width="wrap_content"
android:id="#+id/text_9_description_bottom"
android:layout_toRightOf="#+id/tabchaprter9_row_button_edit"
android:layout_height="match_parent" android:gravity="right"
android:layout_alignParentRight ="true"
android:inputType="text"
android:imeOptions="normal">
</EditText>
</RelativeLayout>
Row Layout contains EditText, checkbox and couple of buttons. ListView is filled with setAdapter (). Apparently ListView is created correctly, I see all rows with data.
First problem : I would like to initially show EditText as disabled so user cant edit text immediately. Only after clicking on "edit" button in the row EditText must became available for typing. Setting enable "false" has no effect on EditText (tried bot in code and in XML attribs) EditText is always editable.
Second issue: Typing in EditText using softkeyboard looks fine - I see all changes, however when I close softkeyboard (either pressing Android back button or "hide" button on keyboard) all added text is removed and EditText is reverted to its initial stage.
rather than enabling and disabling it try with focussable= "false" this will have desirable effect.
For first issue: add this attribute in XML file android:visibility="invisible"
And in the edit button onClickListener make the visibility as edit.setVisibility(View.VISIBLE).
make it clear for 2nd issue
first problem : you cannot disable EditText, write code to show TextView and hide EditText for disable EditText mode and vice versa for enable mode.
Second Problem: go to setting -> language and keyboard under text setting disable other languages and keep Android Keyborad on.

Categories

Resources