AutoCompleteTextView update problem

by Tim » Thu, 05 Nov 2009 01:21:48 GMT


Sponsored Links
 Hi guys

I am completely stuck on this for a few days...any help will be super
appreciated!

I have an AutoCompleteTextView which I want to populate with artist
names based on what the user types. I have a method which makes a call
to the Musicbrainz API which takes a few seconds so I do that in a
separate thread.

The problem is that when I get the list of artist names back from
Musicbrainz, I try and update the ArrayAdapter with a Handler on the
UI thread (which is called from the Musicbrainz thread), but its only
on the next letter entered in the textview that the ArrayAdapter
changes are displayed to the user.


Here is my code:


public void onCreate(Bundle savedInstanceState) {
...
                AutoCompleteTextView actv = (AutoCompleteTextView) findViewById
(R.id.artist_search_text_edit);
                actv.addTextChangedListener(textWatcher);
                adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, new ArrayList<String>());
                actv.setAdapter(adapter);

        }

TextWatcher textWatcher = new TextWatcher() {

                @Override
                public void onTextChanged(CharSequence s, int start, int 
before, int
count) {
                        Thread t = new Thread() {
                                public void run() {
                                        ArrayList<String> names = 
(ArrayList<String>) getArtistStrings
(getInput());
                                        artistNames = names;
                                        messageHandler.sendEmptyMessage(0);
                                }
                        };
                        t.start();
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int 
count,
int after) {
                }

                @Override
                public void afterTextChanged(Editable s) {
                }
        };

private String getInput() {
                EditText artistInput = (EditText) findViewById
(R.id.artist_search_text_edit);
                String artistSearchString = artistInput.getText().toString();
                return artistSearchString;
        }


private void updateTextAdapter(List<String> data) {
                adapter.clear();
                for (String artistName : data) {
                        adapter.add(artistName);
                }
                adapter.notifyDataSetChanged();
        }

        private Handler messageHandler = new Handler() {

                @Override
                public void handleMessage(Message msg) {
                        updateTextAdapter(artistNames);
                }

        };

--



Other Threads

1. Calendar Broadcast Intents

I'm trying to capture when a calendar reminder goes off.  What I'm
trying to do right now is use a BroadcastReceiver and receive an
intent from the calendar.  Is there an intent that gets broadcast when
a calendar reminder goes off?  If so what is its name, or where can I
find it?  Is there a list of all the calendar intents somewhere?
Thanks.

--~--~---------~--~----~------------~-------~--~----~

2. 1dp=1/160 inch ?

In Android documentone, dp is one pixel on a 160 dpi screen.  So I
think 1dp=1/160 inch. Am I right?  Are they different in use?
--~--~---------~--~----~------------~-------~--~----~

3. Hide application in Home dinamically

4. How to set color key for hardware overlay engine?

5. Cupcake and master branch

6. setting ringtones from raw files

7. question about terminal developer