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. Working Around Samsung Double-SD Problem

My thinking was:

if ( android.os.Build.MODEL contains-case-insensitive Vibrant /
Incredible / Galaxy ) {
       if ( dirExists( "/sdcard/sd" ) )
            // use that one
       else if ( dirExists( "/emmc" ) )
            // use that one
}
else {
   // usual procedure
   getExternal...
}

Does that look right ? I don't have any talkative users for testing
yet.

Thanks,

Pent

-- 

2. UriMatcher "match" not working properly

Somehow my UriMatcher is not working properly and because of that I am
not able to do the CRUD operations on my tables.

I have the following structure of packages and classes:

com.arpit.provider : This has a class MyContentProvider which extends
ContentProvider class
com.arpit.tables :
        DatabaseHelper extends SQLiteOpenHelper
        KeyTable implements BaseColumns
        ParticipantTable implements BaseColumns


Now in MyContentProvider, I have done the following:

...
public static final String AUTHORITY =
"com.arpit.provider.MyContentProvider";
...
static{
        UriMatcher uriM = new UriMatcher(UriMatcher.NO_MATCH);
        uriM.addUri(AUTHORITY, "key", 0);
        uriM.addUri(AUTHORITY, "participant", 1);
}
...
public Cursor query(Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder) {
                SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
                switch(uriM.match(uri)){
                        case 0:
                                qb.setTables("key");
                                break;
                        case 1:
                                qb.setTables("participant");
                                break;
                }
....
}
...

In my KeyTable class, CONTENT_URI = "content://" +
MyContentProvider.AUTHORITY + "/key";
In my ParticipantTable class CONTENT_URI = "content://" +
MyContentProvider.AUTHORITY + "/participant";

In my AndroidManifest.xml file I have registered the provider as:

<provider android:name="com.arpit.providers.MyContentProvider"
        android:authorities="com.arpit.providers.MyContentProvider"></
provider>

Now I make the query call with the following statement in my
HomeActivity:

Cursor cursor = getContentResolver().query(KeyTable.CONTENT_URI, new
String[] { KeyTable.col1 }, "_id='1'", null,  null);

My problem is when the Query Method is called and the Switch block is
executed the uriM.match returns always -1 (irrespective of whether it
is KeyTable.CONTENT_URI or ParticipantTable.CONTENT_URI).

Could you let me know what wrong am I doing because of which it is not
working.

they call managedQuery instead of getContentReslover().query(...). I
tried firing managedQuery(...) in my HomeActivity class, but that also
result in uriM.match(uri) to return -1.

It will be great if you could help me out.

Thanks & Regards,
Arpit




-- 

3. Adding checkboxes to a LinearLayout

4. Twitter4j 2.1.4 HttpClietImpl calls wrong Scheme Constructor

5. Versioning and common code-bases with Eclipse

6. How to prevent a service from being restarted by the system...

7. Camera rotation (output and capture)