android上自动完成textview的光标适配器实现



在我的应用程序中,我需要在自动完成textview中填充联系人的电子邮件id。我使用内容解析器在光标中获得电子邮件id。现在我必须为自动完成textview实现游标适配器,以便从游标填充邮件id。我已经尝试了下面的代码,但它没有从光标加载电子邮件id。

我的光标适配器类如下:

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不会超出构造函数。bindView,newView和convertToString方法没有被调用。

在我的主类,我调用适配器类如下方式:

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

我不知道为什么我的代码不加载电子邮件在自动完成textview的原因。

谢谢大家,我已经解决了使用资源游标适配器。

最新更新