How to scroll the content of edittext when you click a button?
You can see the effect in a app called Calulator of android emulator.For example,when you input 'A+B' and then click the button named '=',the content of edittext scroll from 'A+B' to the result of 'A+B'.How to do it?Who can help me?
Here,thanks in advanceļ¼
Sorry!I'm a new programmer.I don't understand your reply a bit.How can I set the coordinates?I set like output.scrollBy(90,90),but it does't turn up a scroll view.
The following is my codes:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="80dip">
<EditText
android:id="#+id/input"
android:layout_gravity="top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorVisible="false"
android:textSize="32dip"
android:singleLine="true"
android:focusable="false"
android:maxLength="17"
android:background="#drawable/image_et1_conf">
</EditText>
<EditText
android:id="#+id/output"
android:layout_gravity="bottom"
android:gravity="right"
android:ellipsize="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorVisible="false"
android:textSize="32dip"
android:text="#string/output"
android:singleLine="true"
android:focusable="false"
android:maxLength="17"
android:background="#drawable/image_et2_conf">
</EditText>
</FrameLayout>
you should try using
editText.scrollby(scrollPixelInHorizontal,scrollPixelInVertical)
on onClickListener of Button
Related
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>
i want focus in the second editText ,also can make edit in the first
I have two edit text , i tried to put in the second edittext
android:focusable="true"
android:focusableInTouchMode="true"
but when tested it still focus in the firstEdit text
<EditText
android:id="#+id/editText1Price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/textView2"
android:ems="10"
android:inputType="numberDecimal" >
</EditText>
<EditText
android:id="#+id/editText2Funds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/textView4"
android:layout_toLeftOf="#+id/textView4"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="number"
/>
this may little help you !
try this in your .java file :
EditText edittxt=(EditText)findViewById(R.id.editText2Funds);
edittxt.requestFocus();
Keep <requestFocus/> in the Second EditText.
try this,you have to add below code in which edittext you show focus..
<EditText...>
<requestFocus />
</EditText>
i used edit text for scroll option, and it display text i wrote.
the problem is that when the activity whith this edit text open
it show the text from the end, and i need to scroll up to see the beginig
thans
this is the code (xml):
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView4"
android:layout_alignRight="#+id/imageView4"
android:layout_below="#+id/imageView4"
android:layout_marginTop="17dp"
android:background="#null"
android:cursorVisible="false"
android:editable="false"
android:ems="10"
android:gravity="top"
android:singleLine="false"
android:lines="8"
android:inputType="none"
android:
android:scrollbars="vertical"
android:text="Some Long String"
android:textColor="#android:color/white" >
You can set the cursor position in your Activity's onCreate() with setSelection():
EditText editText1 = (EditText) findViewById(R.id.editText1);
editText1.setSelection(0);
i used edit text for scroll option
If you only want to let the user scroll through your text, it is easier to use a ScrollView:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
... />
</ScrollView>
I want to make a input pin code input box as per below image .i have used four edittext for it but my problem is that i m unable to move the cursor from one edittext to other and vice-versa.Please help me on this.
I think something like this will do what you want:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
Or do you want to auto-jump from one EditText to another when filled?
what do you mean you are unable to "move the cursor from one edittext to other and vice-versa" ??
Like when you type in one character/number in the edit text so the cursor should jump to next edittext?
If so try getFocus() with implementation a TextWatcher for the EditText, it has a callback that gets called after every letter typed in.
In the affirmation text field I press the newline button and it puts spaces.
However after I click done the field actually has the correct new lines (second screen capture).
Its not a problem with the device as it works correctly for the compose mail filed in the gmail app. Which is how I would like this to work.
<TextView
android:inputType="textMultiLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="#string/edit_affimation"
/>
<EditText
android:id="#+id/affText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:singleLine="false"
>
</EditText>
Figured it out
<EditText
android:inputType="textMultiLine"
android:id="#+id/affText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:singleLine="false">
</EditText>
Add following attribute:
android:inputType="textMultiLine"
You can also do it programmatically:
Editext txt = (EditText) findViewById(R.id.affText);
txt.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);