Reputation: 797
On my contact list application i try to use autocompletetextview when making search of contacts but is not working
here is my 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);
}
});
}
And here is my search.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>
I dont get any error but search anly works when i press search button.but when i start typing a name nothing happens.where is the problem?
Upvotes: 1
Views: 4659
Reputation: 24476
Where are these methods for 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
}
}
Just refer this basic Example
Upvotes: 2
Reputation: 10349
Add the below line in your XML file under AutoCompleteTextView
android:completionThreshold="1"
it may work, try it.
Upvotes: 3