次のコードを使用して、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の更新をオーバーライドする方法について他に何かアイデアはありますか?
ありがとう
パトリック