我正在使用以下代码为 AutoCompleteTextView 设置适配器(SimpleCursorAdapter)
mComment = (AutoCompleteTextView) findViewById(R.id.comment);
Cursor cComments = myAdapter.getDistinctComments();
scaComments = new SimpleCursorAdapter(this,R.layout.auto_complete_item,cComments,new String[] {DBAdapter.KEY_LOG_COMMENT},new int[]{R.id.text1});
mComment.setAdapter(scaComments);
auto_complete_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
这是实际控制的xml
<AutoCompleteTextView
android:id="@+id/comment"
android:hint="@string/COMMENT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"/>
下拉列表似乎可以正常工作,并显示项目列表。当我从列表中进行选择时,我在文本视图中得到一个 sqlite 对象('android.database.sqlite.SQLiteCursor@'...)。任何人都知道会导致这种情况,或者如何解决这个问题?
谢谢
好的,我可以挂接到 OnItemClick 事件,但 AutoCompleteTextView 小部件的 TextView.setText() 部分在此之后更新。OnItemSelected() 事件永远不会被触发,而 onNothingSelected() 事件会在首次显示下拉项目时被触发。
mComment.setOnItemClickListener( new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
SimpleCursorAdapter sca = (SimpleCursorAdapter) arg0.getAdapter();
String str = getSpinnerSelectedValue(sca,arg2,"comment");
TextView txt = (TextView) arg1;
txt.setText(str);
Toast.makeText(ctx, "onItemClick", Toast.LENGTH_SHORT).show();
}
});
mComment.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(ctx, "onItemSelected", Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Toast.makeText(ctx, "onNothingSelected", Toast.LENGTH_SHORT).show();
}
});
任何人都对如何覆盖 TextView 的更新有任何想法?
谢谢
帕特里克