【发布时间】:2013-01-18 13:11:12
【问题描述】:
在我的应用程序中,我需要在自动完成文本视图中填充联系人的电子邮件 ID。我使用内容解析器在光标中获得了电子邮件 ID。现在我必须为自动完成文本视图实现光标适配器,以便从光标填充电子邮件 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);
我不知道我的代码没有在自动完成文本视图中加载电子邮件的原因。请帮帮我。
【问题讨论】:
-
鉴于你的 newView 只是一个膨胀,你为什么不扩展一个 ResourceCursorAdapter 呢?
-
能详细解释一下吗?
-
检查 ResourceCursorAdapter。它会为您充气,基本上它允许您删除 newView 并仅保留 bindView(但这并不能回答您的问题)
标签: android textview android-cursoradapter android-cursor