I am writing a custom calculator Android app. Basically, I have five edittexts, a calculate button and a reset button. I have hooked up the reset button so that onclick of the reset button it sets the value of all five edittexts to "".
How would I go about getting the values of all the edittexts on calculate button click and making an algorithm? Since there are five values, would I need to save each to a sort of temporary cache string?
I am really, really new to this so very plain english is preferable.
Thanks for any reply.
If what you're trying to calculate is a sum, then you should iterate through the Edit Texts (which you can conveniently save in an Array or a Collection... I'd rather go for the Array actually), and, well, add it to the previous value in an auxiliary variable.
I don't get where is the problem. Maybe I'm misunderstanding something. Seeing your current code could help.
Related
My question is quite short and simple but I'm unable to find a solution. I wan to make my EditText looks like this form:
So, every time the user input a char (android:inputType="numberDecimal"), it goes to the next box. (Just display the char into next box no need to display the cursor). It would be nice if this could be done using a single EditBox.
I have no other idea than making 5 liniar EditText controls and add TextWatcher to every one of it forcing it to jump (focus) to the next one. But this seems a less elegant solution and more complex.
Has anyone any other ideea?
Why reinvent the wheel everytime. I guess this has exactly what you want.
just checkout here https://github.com/Philio/PinEntryView as you required "Just display the char into next box no need to display the cursor".
I want to create 16 buttons each have different texts on it.Those text will be picked up randomly from an array depending on another random value.Lets say,
I have 3 words (apple,banana,watermelon), when the activity created it will pick up one of these words.Lets say apple.And in this activity's screen there will be 16 buttons.These buttons must have the letters that apple consists of "a","p","p","l","e" and the remaining buttons will be filled up with other remaining letters of the alphabet.
So in my case what I wonder is should i do the button creation programmatically by taking a value and assigning this value on creation one by one or do it in the xml and leave their text parts and fill up programmatically.
These 2 options in detail :
First : I'm going to create a function which takes a String value as a paramater and returns a button with this text set on it by using setText(); and then locate it in the layout.
Second : I create the layout with those button and leave blank their text parts and in the activity I only assign their letter values.
I vote for the second option but I'd like to know what's your opinion and would there be a difference in terms of performance or memory ?
The disadvantage of declarative approach is that you can get only so
far with XML.
XML is great for look and feel of your user interface, but it does not provide a great way of handling user input. That's where the programmatic approach came.
Everything you can do declarative as well as with programmatically. But java also allows you to specify what happens when the button is actually clicked.
This is the main advantage of programmatic approach to the user interface.
So what is Best ?
Here it is , Both are good at thier point.
1) Use XML , when everything about your user interface is static , such as layout of the screen , all the widget etc.
2) Then switch to the programmatic approach when user interacts with various widget in the user interface.
In other words you would use XML for what the button Looks like and
Java to specify what it does.
I need an advice about ListView.
A give you an example:
Assume that i have a map. If i'll touch some place on it i'll get an information about that place and then, on screen, a dialog fragment will appear. In this dialog i can write a name of place, which i touched. The names should be saved into ListView but if i'll click on some of them i want to get information.
Can some of you tell me how i should do this? Is it possible to save that information in Shared Preferences?
Maybe you would get it work with SharedPref. but it isn't a nice way to that. I think the best way is to create an Android SQL-DataBase. Like in every other Database you could use one column for the name, one for the information text, one for coordinates and so on (that's just an example). The data will stay, also if your app is closed (like SharedPref).
I have a button on my home screen that will add an edit text field every time it is pushed (I limited it to 20 for best practice). It is basically a small budgeting app. I want the user to fill in an X amount of dollars in one of the fields. Then, when they are ready, to come back to the app another time and that created EditText is still there filled with the value. I know how to utilize SharedPerfrences to hold the value. I do not, however, know how to hold that newly created EditText field when the user comes back.
I am acutally going to expand and have a button and a datepicker associated with each EditText field so soon click the button will create three objects, not just one. But I want to get one working first and will apply the principle to the others later. Any suggestions?
Sounds like a good candidate for a SQLite database.
For instance, I use a SQLite database to retain and recall the co-ordinates and types of widgets that the user has arranged within my application.
Note that you don't ever want to be trying to store and recall the actual EditText View object itself. In your database you need to devise your own table format that suits the kind of information you need to store. If you simply need to retain the states of a series of EditText fields then this could be as simple as having a table with just one column that contains a string value on each row. To build your UI up again from that database, you'd loop through and create a new instance of EditText, and set the text of each one from the table.
You would have to use Android Parcelable interface, refer to this to know as of how to implement it, refer to this question which I has asked on StackOverflow, it has a good answer.
Suppose, I need the user to be able to input a list of strings somewhere in the settings of the app. Say, it's a list of URLs. The strings are not supposed to have any spaces, commas or semicolons inside.
The easiest thing I thought of so far is to make a big multi-line EditText with a hint to the user "Separate strings by spaces" and each time the user presses OK, use split(" ") to extract the array of strings.
The problem with that simple solution is that sometimes strings are not long enough to fill the whole EditText width, and >1 strings appear visually in 1 line. Sometimes the URLs are too long, so "www." remains on one line, and the rest of the address appears on the next line. It all looks messy and the user looses track where separate URLs start and end in the line.
Another easy solution: a long single-liner where all strings are separated by ; with optional spaces after. VisualStudio uses that in settings, I find it bad as well since you don't see all the strings at once and have to move in this long line a lot (even harder with the clumsy touch screen).
A more expensive solution: a vertically scrollable list of single-line EditTexts, which are generated programmatically each time the settings screen is opened. Would also need a "+" button which creates a new EditText and a "-" button next to each of the existing EditText's.
EDIT: Another idea: show all the strings in a plain ListView with a "+" button in the last row. When you tap "+", it turns into an EditText with 2 buttons to the right: "OK", "Cancel". "OK" would save the newly added string.
If the user taps any of the items in the list, the line turns into an EditText with "OK" and "Delete" button. "OK" saves edits, "Delete" deletes the item. "OK" and "Delete" buttons better should have images instead of words.
Or, well, all strings can be shown in a ListView, and each time the user taps on an item, an additional popup is shown with EditText for editing the string and 3 buttons below: "OK", "Cancel" and "Delete".
Am I thinking along the right lines? Do you know any existing patterns/libraries/solutions which solve this problem efficiently on touch screens?
It would be better, to have only a single editText, where user can set values in list one by one, and can see added values in listView, There may be some provision for a button to save all entered data, onve. See following link once,
http://www.mubasheralam.com/tutorials/android/listview-transcript-mode
IMHO touch screens are not made for extensive writing since the touch keyboards are awful for writing stuff too long or with too much symbols (e.g. programming language or URL). Do not think about touch apps like old desktop apps/systems. Maybe you should rethink your design and try to avoid this data input.
If it's something your app cannot live without, or you simply do want to do it that way anyway:
I think a newline separator is way more clear than a space or a ";" (assuming the URLs cannot contain ";" btw...).
What about one EditText for each URL, generating EditTexts programatically as the previous one is filled.