Android ListView item highlight programmatically - android

I know it's been asked around but I haven't found quite the answer yet (new to Android so sorry about the ignorance)
my app's launch Activity has an EditText (called searchbox) , a ListView (designations) and a Spinner (types)
I use the EditText as a searchbox, I have to pass the string through a custom editing to make searching more flexible. After that I match that against the closest approximation I find in 'designations' and do
designations.setSelection(j);
As expected, this sets the desired item to the top of designations. But I can't find a way to highlight it via code.
NOW, i do know that if the device is in touch mode the highlighting of a selected item won't occur. So the last 4 lines of my searchbox's onTextChanged event are:
designations.setFocusable(true);
designations.setFocusableInTouchMode(true);
if (match==true) designations.setSelection(j);
if (st.length()==0) designations.setSelection(0);
to no avail.
now, i don't have any code on searchbox's afterTextChanged(Editable s);
so could anyone give me a clue on this?
regards
~dh

check out requestFocus() and maybe requestChildFocus()

Have you tried setting the actual View to be selected?
designations.setSelection(j);
designations.getSelectedView().setSelected(true);

Related

Android Spinners with different Display text from the list values

I'm playing around with Android spinners. I'm not 100% sure if I can get the behavior I want using a spinner, but it's the most obvious choice that comes to mind.
I need something of a dropdown view, the title of which says "x of y selected".
The options in the dropdown would look like:
-All
-None
-Special items only
On clicking one of the dropdown items, the title is reconfigured such that 'x' changes.
It would be ideal to use a spinner, but somehow, it seems that android puts in the first value of the spinner to always be the first values in the list of strings you pass it, and I clearly don't want the title item to be shown in the dropdown list for my case.
Another approach that I came across was to perhaps use a button with a popup with these items in the popup.
Would that be a better approach, or can I actually achieve the behavior using a spinner, or is there another view that would better serve my purpose?
I'm going to redirect to this post, after a lot of searching I found what I was looking for:
How to hide one item in an Android Spinner
The answer by Aebsubis, and make sure to set the text view height to 0. I'll update this answer with more code, once I'm done with tweaking it for my purposes.

Autocomplete/Autofill Edit Text Android

I am looking to achieve the functionality of an AutocompleteTextView but slightly different. Instead of getting a drop-down list with suggestions i want it to complete the sentence for me.
For example: i type abc and i get completed, with the rest of the text in grey: abc1#etc.etc and then click a button to keep this text or keep writing to filter this even further.
Do you think is is achievable somehow?
I have looked my problem up so far but all the answers i found involved a drop-down list, perhaps i haven't looked deep enough.
Why don't you try to implement a custom view?
Basically, you need to the same things that the AutoCompleteTextView does but instead of displaying N elements into the drop down list you have to add the first option to your EditText.
Have a look at:
TextWatcher in order to see how detect the user input and progress
You can then play with indexes and spannables in order to keep track of the data input by the user and the data that you are suggesting.
One thing that I don't like about this idea is the fact that if you have got:
Germans
Germany
...
You need to type a lot of letters without the possibility to choose something different from the solution that you are providing.
use below example ... i think help you...
http://teamandroid4u.blogspot.in/2012/06/autocompletetextview-example.html

Android - call TextWatcher for highlighted text

So I'm new to Android development and I'm currently figuring out TextWatcher.
What I'm attempting to do is attach my TextWatcher listener to an EditText widget and after the user has put in some text, say "Hello" and he highlights "llo" and types in r, I display the change in a TextView widget. For the above example it will display "llo --> r".
Now from what I've read and tried, since the textchangelistener is called every time the user types in something, my code ended up crashing when I ran it on my phone.
Is there a way to call the listener only when the highlighted text is changed so as to avoid calling it every time I'm just typing something in the EditText widget? I hope my question makes sense, I've tried looking around before posting here but I couldn't find anything.
Not looking for code, just some pointers so I can figure out how to do this.
Thanks!
Your best bet would be to use a OnEditorActionListener instead of a textwatcher which I didnt know existed until now. It gets called when there is a change to a textview, and since edit text is a textview than it will work perfectly.
Heres some info on the listener
Btw welcome to the android platform, I think you'll find that it is a rich language and definitely worth learning. If you really want some pointers your main point of reference should be this link which has many guidelines and pointers in the develop tab. Good luck

What is the difference between text field types

I am new to android. I was stuck on a problem but I finally solved it.
I was using a TextField instead of CompleteTextViewField so whats the difference between these two and when should I use each one of them?
Thanks
Neither of those classes you mention (TextField, CompleteTextViewField) exist. Do you mean EditText and AutoCompleteTextView? I think the documentation explains it pretty well:
[AutoCompleteTextView is] An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.
That is, use it rather than a normal EditText if you have a set of common autocompletions for what gets entered in the box. The docs also link to a full sample that shows how to populate that list of suggestions with an Adapter.

Listview, single choice in touch screen?

Goal: have a LIstView show a list of text strings. The user can select an item by touching it. The selected item is visibly different to those not selected.
In short I want to have a simple scrolling list box that works using trackballs AND touch mode.
There are many posts asking for this, but none seem to get an adequate answer. This is such a simple requirement, why is there no article on this?
I looked at http://developer.android.com/resources/tutorials/views/hello-listview.html but that won't work in touch mode: the orange background is displayed, something unachievable in touch mode without extreme geek wizadry, for something that is quite frankly what all newbies expect out of the box.
I suspect that the only way to achive a touch mode selectable listbox (ListView in google speak), is to stick radio buttons in there. All of a sudden my little text list view is beccoming a monster.
Can anyone explain the simplest way to do a single choice ListView that displays the item selected so the user can figure out that it is selected, in touch mode? After fumbling for days, I really am not fussed if it has radio buttons, singing cockatoos, or whatever, so long as it's simple to code.
Here's the example that Google provides:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List10.html
It uses radio buttons
Wat do u want to do? Just highlighting the row in the ListView which is selected.rt? for this u can use this.
android:listSelector="#drawable/highlighter"
android:drawSelectorOnTop="true"
Write this code in your XML file

Categories

Resources