I'm a beginner and am making a calculator (fairly easy), but it's happening the following problem: When Cline in "1" button for example, he enters this number in the EditText, but if you click again the number is overwritten instead of the inserted his side as desired. How do the numbers were placed side by side without overwriting those already there?
Note: The layout of buttons and etc. I did in. XML, so I'm not using the keyboard native Android.
Thanks!
when you want to add a new number next to the old one, you probably need to
get the value that is currently being shown in this "edit text" and save it in a string
concatenate this old value with the new one that you want to add to your "edit text"
set this new concatenated value as the new text in your "edit text"
:)
Related
Currently working on an Android app. I want a page to have a button, and when clicked on, I want it to create a form. When they press the button again, it will create another form, and so on. Just like when you are on a website, and add your emails or anything, and you press "add" button, which will create a new input field each time.
Also, next to the input field has a name (same for each time) like
fieldName: [___input_field____]
fieldName: [___input_field____]
...
(+) //there is a button, and pressing this button will create a new form above.
I am not sure how to go about this. I want each input field to have a different ID, but is it possible? Each input field is going to be filled with a number, and in the end, I want to add all numbers in the form to find the average of them.
it will be easier and cleaner create a child layout with your form and inflate that child every time you need a new form and to get each item you can use View.getChildAt(position);
http://www.android-examples.com/create-edittext-dynamically-using-java-file-in-android/
This link shows a simple way to add an edittext dynamically. For what you have mentioned above, you have to use edittext array and for each "add" click, create edittext like et[i] = new EditText()...
Then on final submit click retrieve edittext datas from this editext array
Wherever your carret on a name that you want to change is
if you call for autocomplete (ctrl + space)
you will get a new full name instead of the only the part after carret(which is needed in this example)
The only possible way to choose another name in a clean way is to place carret at the end of the previous name
but when you want to change a name from the middle of the previous name
you have no choice other than accept the suggested name
and then delete the residue text from the previous name
Comparing previous text with new selected text from autocomplete suggestion box is implemented on many code editors. Is there any specific reason that Android Studio team decided to not to implement this feature? or may be this feature exist but is turned off by default for some reason and if this is the case how could we turn it on?
Just use TAB instead of ENTER to autocomplete changing the old value. It also works for methods.
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.
I am tyring to accomplish a part of my app where the user can input a maximum number of 10 players names but each name will be limited to a maximum of 12 characters. Once the user has inputed each name they will start to appear next to the input box in a kind of listview (not sure if this would be the best way) with a remove button. Also when each name is enterd I need that to have been saved into a string/array as these names will need to been showen in the next Activity.
My question is does anybody have any experience with this or any suggestions as where to start?
Not sure what kind of input method I should be using would a EditText be OK?
<EditText
android:id="#+id/userinput"
android:layout_width="190dp"
android:layout_height="40dp" >
<requestFocus />
</EditText>
Also I have been reading around differernt methods such as SoftKeyboard or the InputMethodService class just not sure where to start with this?
EditText will be fine. You could either use 12 different EditText boxes, 1 for each player, or you could make just 1 box and clear it every time a name is saved.
Just have a confirm button next to the/each EditText, and write an onClickListener so that when that button is clicked, you take what's in the EditText and add it to the array (clearing the EditText if you need to).
For the remove player button, simply add buttons next to the list, and give each button an onClickListener which removes the corresponding address in the array, remembering that array addresses start at 0.
If you need a little help with some of the code, let me know which part you're stuck on.
Pretty new to android so excuse me if this is a really obvious question.
Say my application has a bunch of TextViews, each one showing the attributes of a certain product (name, price, etc). I have a button next to each of these TextViews labeled "modify".
How do I make it so that when I press the modify button next to a certain attribute, a popup window with a space to enter text into comes up so that the user can enter text into this box and then have the actual attribute listing on the original page change? Actually I just need a push in the right direction with creating this popup text field... not sure if there is already some built in functionality for this or if not, what would be the best way to create this kind of thing.
Thanks.
Why not have the modify button set TextEdit.setEnabled(true); and then change focus with TextEdit.setFocus? Note that both of these are inherited from view
If you really want a dialog you might want to looking into the AlertDialog.Builder. I know you can use it with buttons and radio buttons, but I'm not sure you can get it to work with a TextView.
Use a code like this for the input popup: Android dialog input text
In the positive button handler, set your edittext content programmatically like this:
myEditText.setText(value).
As simple as that. The only difference with a standard GUI framework is that you don't retrieve the value as a result of the popup function. Instead, you must provide an action handler.