Search code examples
androidtextviewandroid-cursoradapterandroid-cursor

cursor adapter implementation for autocomplete textview on android


In my app i need to populate email ids of contacts in an Auto complete textview. i got email ids in a cursor using content resolver. now i have to implement cursor adapter for auto complete textview for populate the email ids from the cursor. i have tried the following code but it didn't load email id from cursor.

my cursor adapter class is as follows:

public class AutoEmailAdapter extends CursorAdapter{
private LayoutInflater inflater;

public AutoEmailAdapter(Context context, Cursor c) {
    super(context, c);
    inflater = LayoutInflater.from(context);
    Log.e("adapter", "18");
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    Log.e("","bindview");
    String t = cursor.getString(1);
    Log.e("adapter @ 23", t);
    ((TextView) view).setText(t);
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    Log.e("","newview");
    inflater = LayoutInflater.from(context);
    final TextView view = (TextView) inflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
    String te = cursor.getString(1);
    Log.e("@33",te);
    view.setText(te);
    return view;
}

@Override
public String convertToString(Cursor cursor) {
    Log.e("","convertTostring");
    return cursor.getString(1);
}

}

android does not go beyond the constructor. The bindView,newView and convertToString methods didn't called.

in my main class i called the adapter class as in following way:

  AutoEmailAdapter adapter = new AutoEmailAdapter(MainActivity.this, cursor_emailIds);
  emailId.setAdapter(adapter);

I do not know the reason why my code does not load email in the auto complete textview. please help me.


Solution

  • Thanks everybody i have solved by using Resource cursor adapter.