2012-01-04 2 views
1

в списке контактов приложения я пытаюсь использовать AutoCompleteTextView при выполнении поиска контактов, но не работаетавтозаполнения вид текста не работает

вот мой Search.java:

public class Search extends ListActivity { 

private static int[] TO = {R.id.name }; 
private static String[] FROM = {DbConstants.NAME, DbConstants.PHONE, DbConstants.EMAIL,_ID}; 
private Button sButton; 

private ListView lv1; 
private static SQLiteDatabase db; 
    private DbCreate contacts; 
    private Cursor cursor; 
    private AutoCompleteTextView searchText; 
    protected SimpleCursorAdapter adapter; 


protected void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.search); 

    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,new String[] {DbConstants.NAME}); 
    searchText=(AutoCompleteTextView)findViewById(R.id.searchtext); 
    searchText.setAdapter(adapter); 

    sButton=(Button)findViewById(R.id.searchButton); 
    sButton.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      showDatabaseContent(); 
       lv1 = getListView(); 

       lv1.setTextFilterEnabled(true); 
     } 
    }); 





} 

А вот мой поиск .xml:

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

     <AutoCompleteTextView 
    android:id="@+id/searchtext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:hint="@string/searchDefault"> 

    <requestFocus /> 
     </AutoCompleteTextView> 
     <Button android:id="@+id/searchButton" 
     android:icon="@drawable/search" 
     android:text="Search" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
     </LinearLayout> 
     <TextView 
    android:id="@android:id/empty" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/empt" /> 
     <ListView 
android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

    </LinearL ayout> 

Я не получаю какие-либо ошибки, но поиск anly работы, когда я нажимаю поиск button.but когда я начала не вводить имя ничего happens.where это проблема?

ответ

2

Где эти методы AutoComplete TextView

@Override 
public void afterTextChanged(Editable arg0) { 
// TODO Auto-generated method stub 
} 

@Override 
public void beforeTextChanged(CharSequence s, int start, int count, 
    int after) { 
// TODO Auto-generated method stub 
} 

@Override 
public void onTextChanged(CharSequence s, int start, int before, int count) { 
// TODO Auto-generated method stub 
} 
} 

Просто смотрите этот основной Example

+1

Почему сайт для разработчиков Android не говоря уже о том, что в данном примере. И они говорят, что это сработает !! http://developer.android.com/guide/topics/ui/controls/text.html – hasan83

+0

Забудьте последний комментарий. проверьте мой ответ. – hasan83

+0

@hasan Где я хочу его проверить? – Praveenkumar

3

Добавьте строку ниже в файле XML под AutoCompleteTextView

android:completionThreshold="1" 

он может работать, попробуйте.

+0

ее не работает – jonny

Смежные вопросы