android上自动完成文本视图的游标适配器实现
在我的应用程序中,我需要在自动完成的文本视图中填充联系人的电子邮件ID。我使用内容解析器在游标中获得电子邮件ID。现在我必须为自动完成文本视图实现游标适配器,以便从游标填充电子邮件ID。我尝试了以下代码,但它没有从游标加载电子邮件id 我的游标适配器类如下所示:android上自动完成文本视图的游标适配器实现,android,textview,android-cursoradapter,android-cursor,Android,Textview,Android Cursoradapter,Android Cursor,在我的应用程序中,我需要在自动完成的文本视图中填充联系人的电子邮件ID。我使用内容解析器在游标中获得电子邮件ID。现在我必须为自动完成文本视图实现游标适配器,以便从游标填充电子邮件ID。我尝试了以下代码,但它没有从游标加载电子邮件id 我的游标适配器类如下所示: public class AutoEmailAdapter extends CursorAdapter{ private LayoutInflater inflater; public AutoEmailAdapter(Context
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);
我不知道我的代码没有在自动完成文本视图中加载电子邮件的原因。请帮助我。感谢我使用资源游标适配器解决的所有问题 既然您的newView只是一个充气工具,为什么不扩展ResourceCursorAdapter呢?请您详细解释一下?检查ResourceCursorAdapter。它为您充气,基本上它允许您删除newView并仅保留bindView(但这并不能回答您的问题)