tags:

views:

116

answers:

1

Hi Friends....

I am working on AutoCompleteTextView.Its working fine and doent give any error.Now the problem I am facing is,suppose we have 3 words starting from "A",when I start typing the letter "A",It shows all the three words.If we have three words like "An","Am","Az",when I type "n" after "A",two other words should be removed from the list.and it should display only "An".But those two letters are not disappeared in my AutoCompleteTextView.What should I do???

Any one have any idea????

Thanks in Advance Nemat

A: 

Ya, sure.Here is my code: String[] phonesProjection = new String[] {Contacts.People.Phones.NUMBER, Contacts.People.Phones.TYPE,Contacts.People.Phones.DISPLAY_NAME, Contacts.People.Phones._ID,Contacts.People.Phones.LABEL }; Cursor phonesCursor = content.query(Contacts.Phones.CONTENT_URI, phonesProjection, null, null, null); ContactListAdapter adapter = new ContactListAdapter(this, phonesCursor);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.edit);
textView.setAdapter(adapter);

public static class ContactListAdapter extends CursorAdapter implements Filterable {

    public ContactListAdapter(Context context, Cursor c) {     
     super(context, c);   

     mContent = context.getContentResolver();     
     }      
    @Override   
    public View newView(Context context, Cursor cursor, ViewGroup parent) {    
     final LayoutInflater inflater = LayoutInflater.from(context);       
     final TextView view = (TextView) inflater.inflate(             
       android.R.layout.simple_dropdown_item_1line, parent, false);  
     Log.i("Cursor Count",""+cursor.getCount());
     view.setText(cursor.getString(2)+" "+cursor.getString(0));         
     return view;     
     }      
    @Override     
    public void bindView(View view, Context context, Cursor cursor) {  
     ((TextView) view).setText(cursor.getString(2)+" "+cursor.getString(0));      
     }       
    @Override     
    public String convertToString(Cursor cursor) {      

     return "";
     }     
    @Override  
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {    
     if (getFilterQueryProvider() != null) {    
      return getFilterQueryProvider().runQuery(constraint);      
      }           
     StringBuilder buffer = null;    
     String[] args = null;        
     if (constraint != null) {    
      buffer = new StringBuilder();    
      buffer.append("UPPER(");         
      buffer.append(Contacts.People.Phones.DISPLAY_NAME);    
      buffer.append(") GLOB ?");          
      args = new String[] { constraint.toString().toUpperCase() + "*" };  
      }           

        String[] phonesProjection = new String[] {Contacts.People.Phones.NUMBER, Contacts.People.Phones.TYPE,Contacts.People.Phones.DISPLAY_NAME,
             Contacts.People.Phones._ID,Contacts.People.Phones.LABEL  };
        Cursor phonesCursor = mContent.query(Contacts.Phones.CONTENT_URI, phonesProjection, null, null,Contacts.People.Phones.DEFAULT_SORT_ORDER);
        int phonesCursorCount = phonesCursor.getCount();
        System.out.println("phonesCursorCount="+phonesCursorCount);
        return phonesCursor;
     }     
    private ContentResolver mContent;   


    }
Nemat
you should put this into your question (you can edit it), not posting it as an answer.
ax