Scroll horizontal in disabled edittext - android

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

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 make Android EditText expand vertically when full

I have this EditText
<EditText
android:layout_width="match_parent"
android:layout_height="72dp"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:inputType="textImeMultiLine"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
When the box is filled up with user inputted text, it scrolls to the right to make room for more text, I do not like this behavior, and would prefer it if the EditText box expanded upwards when it needs more room? Is there a way to do this? Thanks.
Yes, this actually involves two things:
Making the EditText accept multi-line input.
Having its height grow as more text lines are added.
Therefore, to achieve this, you need to set up:
android:inputType="textMultiLine"
android:layout_height="wrap_content"
(Be mindful of the difference between textMultiLine and textImeMultiLine).
The full XML snippet would be:
<EditText
android:layout_width="match_parent"
android:inputType="textMultiLine"
android:layout_height="wrap_content"
android:hint="#string/write_message"
android:textColorHint="#color/primary_color"
android:ems="10"
android:imeOptions="actionDone"
android:id="#+id/message_input"
android:layout_gravity="center_horizontal"
android:backgroundTint="#color/primary_color"/>
Use both flags: textMultiLine will wrap your input, and textImeMultiLine will provide a break-line key in your keyboard.
<EditText
...
android:layout_height="wrap_content"
android:inputType="textImeMultiLine|textMultiLine"
... />
In my case I have multiline text, but it showed one line and a keyboard:
Though I have already set android:inputType="textCapSentences|textAutoCorrect|textMultiLine", it didn't help. Then I understood that when the keyboard appears in DialogFragment, it collapses the EditText. See DialogFragment and force to show keyboard to show keyboard when DialogFragment shows.
Then I added a short delay (100-300 ms) before showing the keyboard. Now I have:
In AndroidManifest I set android:windowSoftInputMode="adjustResize" for current activity.

How to display multiple lines of text with scrolling in android?

I want to display multiple lines of text in my application in particular range such that user can scroll to view other lines. I have tried EditText, but it generates keyboard on top of it and doesn't scroll properly. Then I tried TextView, it also does not scroll the text properly as I wanted.
Is there any other option available? If No, then how to scroll the text vertically in TextView or EditText? I want to scroll the text on drag as in WebView. NOT auto scroll.
You can limit the Height of TextView to match the number of lines you user wants to see, then simply put your TextView in a ScrollView
I had done a simple example to demonstrate this...
<ScrollView android:layout_height="30dp"
android:layout_width="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:textSize="16sp"
android:id="#+id/tv1"
/>
</ScrollView>
Check below code
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:textSize="17dip"
android:inputType="textMultiLine"
android:scrollbars="vertical"
/>
It is possible to create multiline text view with scroll view. I used the following code in your application:
Txt_VistaRecetasola = (TextView) findViewById(R.id.txt_vistarectsola);
Txt_VistaRecetasola.setMovementMethod(ScrollingMovementMethod.getInstance());
Txt_VistaRecetasola.setScrollBarStyle(0x03000000);
Txt_VistaRecetasola.setVerticalScrollBarEnabled(true);
Txt_VistaRecetasola.setTextColor(0xFF000000);
Try using Edittext with making it un editable, so in this case it wont allow keyboard to popup.
android:windowSoftInputMode="stateAlwaysHidden" in your Manifest file in the activity where you have your EditText.

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