I'm working on a application project as my bachelor thesis and I wonder if it's possible to set a text in a Edittext box?
I'm not talking about the editText.setHint("My text"), or android:hint in the XML. I want to fetch a variable from a Web Service (This variable may change depend on what you do ).
For example. You have a shoppinglist. The list says "Go buy two pieces of bread ", and the editText Box is supposed to have " 2 " in the box (so you can directly proceed from there) but if you didn't buy two pieces of bread, you can edit it to " 1 ".
It's hard to explain this, but I hope you guys understands. If not, let me know and I'll try to explain again.
Thanks in advanced!
Just use
EditText editText = (EditText)findViewById(R.id.edit_text_id);
editText.setText("1");
simple:
EditText editText = (EditText)findViewById(R.id.your_edit_text_id);
editText.setText("1", TextView.BufferType.EDITABLE);
Related
I am wondering why Android doesn't support this.
To explain my problem. I am working on an accessibility feature for an Android app.
I have a TextView that displays a number value like 123456.
If I use TalkBack, it will always read just this number value.
What I want it to give this value a context so that TalkBack would read something like: "Number value 123456" I am not able to do that as contentDescription just overrides the text value and hint attribute is read after the value like: "123456 Number value".
Is there an alternative for this? Let me also say that the app is not using a separate TextView which would say "Number value" that TalkBack could read.
The solution I did was to use
var number = 123456
textView.contentDescription = "Number value ${number}"
I am writing my data in a database and getting it in android to set it in a textview but when I write for example:
"hello,
how are you?"
which means each line on a row if the row in the phone completes I get an extra line space and I don't want this need to remove it how can I do that?
thanks.
EDIT:
how can I place a line space in an arabic database: I added \n didn't work "\n" didn't work '\n' didn't work!! any ideas?
even if the database wasn't arabic that didn't work so can I place the \n in the database in a way that the android program takes it as a line space?
Edit2
Is there any other method? other than the one that I've mentioned in my answer? thanks.
check to see if you insert to your DB with that extra line.
showing more code would help us understand whats causing your issue...
but if you want to brute force it you could always use substring() for each or your elements or
`String input = EditTextinput.getText().toString();
input = input.replace(" ", "");`
but like #Nitin Sethi said more code especially the entry to your DB would give us a better understanding of what's going on
so what I did is that I've added the word "line space" in my database and I added
in my android code:
String input = //here I take the cde from cursor;
input = input.replace("line space", "\n");
and it worked perfectly but is there another way?
I am developing one android application. In which I have some Products and form to purchase that product. In the Order form I have one Edit Text as Product ( means product name) .
In my application user has to type Product name but I want to know that Is there any way that
the EditText field is autofilled with that particular Product like as in flipcart.
Any one knows then suggest me...
Thanks in advance...
When you want to populate it just call (after reading it in from the XML layout in this example):
EditText myTextBox = (EditText) findViewById(R.id.editBox);
myTextBox.setText("My Product Description");
If what you are looking for is an auto completion after they have started typing, then an AutoCompleteTextView is your best bet, replacing the EditText and providing the auto complete functionality
There is an example of this over at the Android Developers website:
http://developer.android.com/guide/topics/ui/controls/text.html#AutoComplete
you can use autocomplete textview for suggestion of your all the product names, refer this example http://saigeethamn.blogspot.in/2010/05/auto-complete-text-view-android.html
or you just want to show when app launches, use hint
android:hint="#string/enterproduct"
I Dont get u clearly..
Sooo.
If u want to show text that which user has to fill use Hint.
android:hint="Enter any Filpcart Item"
OR
If u need auto complete text then use above link #kumaand.
Here you can use "input type" in XML design according to the text field.
Add into the XML file
android:autofillHints="emailAddress"
or
android:autofillHints="password"
I'm using SearchView widget (new in Honeycomb). I can set initial text by setQuery, that works.
But is there some way to select all text inside (similar to EditText.selectAll)?
I'd like to give user preset text from previous search, yet easy way to type new text without need to delete old.
You just need to capture the inner EditText, then do anything you want.
EditText edit = (EditText)searchView.findViewById(R.id.search_src_text);
edit.selectAll();
A little late but i had a similar issue.
I'd like to give user preset text from previous search, yet easy way to type new text without need to delete old.
I found a solution that worked for me. You just need to access to the inner EditText and then select all the text in usual way.
To do this try something like the following.
Please note that my code is in c# not in Java but its similar.
int id = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
EditText editText = searchView.FindViewById<EditText>(id);
editText.SelectAll();
In Java it should be something like this:
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) searchView.findViewById(id);
editText.selectAll();
I have just testet it on API level 15! But i think it works on lower levels, too.
What you want to do works well on PCs, but but is not very convenient on touch devices.
I'd use suggestion provider to allow user to reuse recent searches, possibly with query refinement enabled.
I've searched high and low for something that seems to be a simple task. Forgive me, I am coming to Android from other programming languages and am new to this platform and Java.
What I want to do is create a dialog pop-up where a user enters text to search for and the code would take that text and search for it within all the text in an EditText control and if it's found, highlight it.
I've done this before, for example in VB and it went something similar to this pseudo code:
grab the text from the (EditText) assign it to a string
search the length of that string (character by character) for the substring, if it's found return the position (index) of the substring within the string.
if found, start the (EditText).setSelection highlight beginning on the returned position for the length of
Does this make sense?
I just want to search a EditText for and when found, scroll to it and it'll be highlighted. Maybe there's something in Android/Java equivalent to what I need here?
Any help / pointers would be greatly appreciated
grab the text from the (EditText) assign it to a string
Try the code sample below:
EditText inputUsername = (EditText) findViewById(R.id.manageAccountInputUsername);
inputUsername.getText().toString()
^^ Replace the IDs with the IDs you are using.
After this, you have the standard string methods available. You could also use Regex for a complex search query:
http://developer.android.com/reference/java/lang/String.html
http://developer.android.com/reference/java/util/regex/package-summary.html