I am trying to build an on screen keyboard, for a simple counter application, that adds some points for 2 diffeent teams in 2 columns.
The design thing is pretty simple, but it seems hard for me to programm the buttons, in order to insert numbers properly.
I have added all the necesery OnClickListeners and used for example this code for number 1
editText1.setText("1");
But, when i try to press the 1 button multiple times, it doesn't type 111 etc. It keeps replacing the last number that was inputed. So if i press 1 and then 2, it just replaces 1 with 2.
Any idea on how this can work please? :D
setText sets the text. It doesn't append the text. If you want to append, use editText1.setText(editText1.getText()+"1");
Related
I am new around I am trying to create an app to do several things
1
when I choose the first button it will randomly choose a letter, eg. a the second button will do the same from an another text eg. b and a third button call generate will shuffle the letters and we can have either ab or ba word, that words will generate in a text label.
2
same things but several choose buttons (letters a,b,,d,e,f etc.), maybe 5! generation button again and shuflle letters and generate 5 differents words(abcdef-fbdacf etc.) in differents text labels
I am stuck please help me.
this is a part of my project
Input action should happen like thisMobile Automation: I have a a scenario where i have to send keystrokes(inputs) from SoftKeyboard of an android device (like inputs from a real User). I tried with KeyEvent, SendKeys, androidkeycode, adb Shell input, Keys. Everything works fine, but i do not see any character pressed from a soft keyboard. Pls, help me to get solution for this.!!
The need: You need to simulate a press on the on-screen keyboard (using driver.tap())
The problem: Cannot get the Xpath or ID's of a on screen keyboard which puts us in a difficult situation.
Since i've struggled with this same problem in the past, i will advise you to create a function that calculate where each Key is located and press on it using the coordinates.
To be more clear:
Get the coordinates of lowest element you can find -> the keyboard itself is below it -> we can now know the height of the keyboard.
get the width of the screen
now, lets say you have a total of 4 rows(first row is q,w,e..) so we will divide the height by 4.
lets say you want a key from the first row which has 10 keys total, now dived the screen width by 10.
now you need to map each key to its location in a row. After that, call this function for each key you want to press.
I understand that it's ugly, and you will struggle with it a bit, but I don't know another solution to your problem.
I am working on a project and I've gotten a decent amount of the way through, I just have two questions right now that will put this part of the project to rest. For both of these questions I'll make a note saying that I have a text file called "gameslist.txt" in the assets folder. From what I've seen that is useful information to have when asking a question.
Q1: I want to create an array of Buttons with each button's text being the next line in the text file when the activity is created. So, the first button's text will be the first line in the text file, the second button's text will be the second line of the text file, so on and so forth for each line of the text file. There are 3622 lines of text in the file.
Q2: I have a series of buttons (# - Z). How can I get it so that when the user taps one of the buttons the only lines from the text file starting with that letter (or in # case anything that doesn't start with a letter) are shown?
I hope people can help me with this, and if you can help me with only one of my problems, that's fine. Thank you :)
You'll want an ExpandableListView for this. So you'd ultimately have 3622 items divided into 26 (letters) + 10 (numbers) groups. However, that's still a very large amount of items to load. Search for tutorials on ExpandableListView, the bulk of your working code will be in the ExpandableListAdapter.
I'm trying to design a calculator app in Android to learn Java and Android at the same time but I do have prior experience with C++.
So far I've got two TextView elements. One displays the answer and one displays the input. However I don't want to use the user keyboard. I want to have my own buttons that navigate the input field. This is pretty standard for calculator apps.
If the user puts in 3+45/2.45*tan(9) that is put into a string array that would read
{3, +, 45, /, 2.45, *, tan, (, 9, )}. This is then validated, and processed by an RPN function when the user pushes equals.
Now this displays all nice, however I can't figure out how to implement a backspace or arrow keys that would navigate this input TextView field. I need to know where the cursor is which I'm not sure can even be enabled with TextView. Do I need to switch over to EditView? I want functionality so the cursor would skip over functions with one arrow push and delete functions with one push of delete but still navigate non-functions with single presses. For example, when pushing backspace on tan, it should delete all of tan, and not just leave "ta".
Any ideas on where to start?
You can get the Cursor position using the getSelectionStart() and getSelectionEnd() methods. If no text is highlighted, both getSelectionStart() and getSelectionEnd() return the position of the cursor.
Also, take a look at TextWatcher class. Its what Android uses, for per example, auto-formatting/adjusting phone numbers while typing etc.
Here you can find a list of TextWatchers used in Android to give you an idea;
http://grepcode.com/file/repo1.maven.org/maven2/com.google.android/android/2.2.1/android/text/TextWatcher.java
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.