How to calculate the dynamic edit text values in android - android

I have created the dynamic EditText and entered the some value in it.Then If click new button the same EditText box will be displayed below to already existingEditText` also I entered the some value in that box also.I want to calculate the both value when i click total button.

Below is the pseudo operation
Make an Array of EditText first like this:
EditText arrayEditexts[];
After that on Create EditText Button do like this:
arrayEditext[0]=new EditText();
arrayEditext[1]=new EditText();.......arrayEditext[n]=new EditText();
Then on total button's click do like this:
arrayEditexts[0].gettext().....arrayEditext[n].gettext();//do what you want

Related

How to change the focus from edittext view

I have a one textview two edittext fields. am using first for the taking input text from user .
for the Second view I made the focusable set to false and I wrote a onClickListener which pops up(Date Picker) so that user can set the date.
Scenario:
I first I click on the first edit text and I start typing some text when am done I click on the second edittext and a I get a popup(Dialog) I select the date and click set on the dialog.
My Problem here is : After setting the Date, focus is still in the first field.
What I have tried.
-- While implementing the onClickListener for the second edittext , I tried to change the focus to the textView.
textview.requestFocus();
but it din't work.
Is there a way I can change it ?
if you don't want to enter date manually.. than make that Edittext to Enable false.
editText.setEnabled(false);
editText.setFocusable(false);
editText.setInputType(InputType.TYPE_NULL);
and just set the text on edittext from datepicker dialog..

Get EditText ID in which Cursor is blinking

I have four edit text. And one button .
First:On Click of button I want to set the Button Text to EditText in which cursor is blinking.
Second: After reaching MaxLength character of Edit text automatically set focus to next edit text.
Any Idea how to do that?
Make a list of all TextEdit, then search for selected:
http://developer.android.com/reference/android/view/View.html#isSelected()

Single-choice list with input-field

When the user hits a button in my app, it shows a persistent single-choice-list with use of AlertDialog.Builder and the setSingleChoiceItems()-method. The list is populated with values from a simple array, which is not known at compile-time. When the user hits "OK" in the dialog, the value is saved.
Now, I would like an option in this list where the value is a textbox and not populated from the array. Is this anyhow possible, and which way should I go?
I've tried to sketch it here:
[] option a
[] option b
[] option c
[] "TEXTBOX HERE"
Well it can get complicated but, here it is..
You can add onClickListener to that radiobutton and set its text like "Enter the text".
Then, in in onclick() open a custom dialog box which accepts text. then set value received from there in your radio button text by radioButt.setText(value entered);.
Custom Dialog example. in here just add editText in place of image view and text view.

Android Calculator using textview

I am trying to build a calculator app. i use textview to recieve the value from button, whenever user click on button. but when user click on the button second time then the value in textview is overwritten by the value of the previous button.
But i want to get the whole value in textview.
Ex: Suppose user click on the 1 then 2,then 3 so number appear in textview will be 123.
So please guide me.
when user click on the button second time then the value in textview is overwritten by the value of the previous button
Use append() instead of setText() to add on to the existing string in your TextView.
To do this you need to add the number to the string in your textview, instead of replacing it. Put the following in you onClick method for each button
String s = textview.getText().toString();
textview.setText(s + "1")

Curser position in EditText

I have an EditText that the user can write in,
when the app starts there is already a string in the EditText.
When the user clicks the EditText it becomes focused and the curser is where the user clicked the EditText text box.
I want the the curser will be at the beginning of the EditText regardles to where it was clicked.
How can I set the curser position upon clicking the EditText text box ?
If the above doesn't work try:
editText.setSelection(1);
editText.extendSelection(0);
editText.setSelection(0);
This should achieve what you want:
editText.setSelection(0)

Categories

Resources