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. Problem in nesting LinearLayout?

Hi,

I am facing a problem in designing LinearLayout. What I want is the
Textbox at the top and button bar at the bottom. But the top Textbox
just don't appear.

The xml file looks like this :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:layout_width = "fill_parent"
        android:layout_height = "fill_parent"
        android:orientation="vertical"
        android:background = "#ffffff">

        <LinearLayout
           android:id="@+id/button_bar"
           android:layout_width="320dip"
           android:layout_height="50dip"
           android:orientation="horizontal"
           android:gravity = "bottom"
           android:padding="0dip"
           android:background = "#FFFFFF"
           style="@android:style/ButtonBar">

           <Button android:id="@+id/mapbtn"
                   android:layout_width="80dip"
                   android:layout_height="50dip"
                   android:layout_weight="1"
                   android:background = "@drawable/mapbtn"/>

           <Button android:id="@+id/mebtn"
                   android:layout_width="80dip"
                   android:layout_height="50dip"
                   android:layout_weight="1"
                   android:background="@drawable/mebtn"/>

           <Button android:id="@+id/friends"
                   android:layout_width="80dip"
                   android:layout_height="50dip"
                   android:layout_weight="1"
                   android:background="@drawable/friendsbtn"/>

           <Button android:id="@+id/privacy"
                   android:layout_width="80dip"
                   android:layout_height="50dip"
                   android:layout_weight="1"
                   android:background="@drawable/privacybtn"/>
         </LinearLayout>

    <LinearLayout
                        android:id="@+id/searchbox"
                        android:layout_width="320dip"
                        android:layout_height="44dip"
                        android:orientation = "vertical"
                        android:gravity = "top"
                        android:background = "#96A2B5">

                        <EditText
                                android:id = "@+id/searchtxt"
                                android:layout_width = "260dip"
                                android:layout_height = "31dip"
                                android:lines = "1"
                                android:maxLines = "1"
                                android:layout_marginLeft = "5dip"
                                android:layout_marginTop = "8dip" >
                        </EditText>
        </LinearLayout>

</LinearLayout>

I just don't understand what is the issue over here. I think its
something to do with android:orientation parameter, but I don't what
is it.

Can someone here please point out the mistake in this and let me know
the solution for this.?

Hope to get a quick reply.


Regards
Sunil


-- 

2. problem with OnclickListener in Gridview

Dear friends,
     I am facing a problem with the onclicklistener in GridView. I am
creating a folder browser for my ImageViewer.I want to create a custom
folder icon that is formed from 4 bitmaps of which 2 are of the any
two images in the  folder. So i created an "EfficientAdapter" that
extends a baseadapter. In efficient adapter getView, i am loading the
required images and creating the view. I have made the folder icon as
a xml and will only load corresponding bitmaps in the getView. so i
use layoutinflator to get the folder icon as a view and get individual
bitmaps and load images to it.Now the problem i am facing is that my
gridview does not seem to take Clicklistener. If i use a simple
bitmap, instead of a layout as an element of gridview, then it accepts
the clicks, but if i use the layoutinflator, then it does not.Please
let me know if anyone has come across any similar issue. Thanks in
advance,

Joseph

-- 

3. getNetworkOperator() in airplane mode always crashes

4. Update Activity from BroadcastReceiver

5. Suhu SA langsung memberikan tips n trics

6. flow of control in CTS

7. Multi-APN support on Android Eclair