Tôi đang sử dụng đoạn mã sau để thiết lập các bộ chuyển đổi (SimpleCursorAdapter) cho một AutoCompleteTextViewAutoCompleteTextView màn 'android.database.sqlite.SQLiteCursor @' ... sau khi thực hiện lựa chọn
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"/>
và thi là xml cho sự kiểm soát thực tế
<AutoCompleteTextView
android:id="@+id/comment"
android:hint="@string/COMMENT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"/>
các d ropdown xuất hiện để hoạt động chính xác và hiển thị danh sách các mục. Khi tôi thực hiện lựa chọn từ danh sách, tôi nhận được đối tượng sqlite ('android.database.sqlite.SQLiteCursor @' ...) trong chế độ xem văn bản. Bất cứ ai biết điều gì sẽ gây ra điều này, hoặc làm thế nào để giải quyết vấn đề này?
nhờ
Ok tôi có thể móc vào các sự kiện OnItemClick, nhưng TextView.setText() phần widget AutoCompleteTextView được cập nhật sau thời điểm này. Sự kiện OnItemSelected() không bao giờ bị sa thải và sự kiện onNothingSelected() được kích hoạt khi các mục thả xuống được hiển thị lần đầu tiên.
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();
}
});
Bất kỳ ai cũng có ý tưởng về cách ghi đè cập nhật TextView?
nhờ
patrick
Vâng, bạn là chính xác. Tôi chỉ đơn giản là chọn một trong các tùy chọn từ spinner được tạo ra như là một phần của AutoCompleteTextView. Ở đâu hoặc làm thế nào để tôi chặn các chức năng để xử lý việc lựa chọn; sử dụng getString() trên con trỏ, trước khi nó được đặt làm văn bản của điều khiển. Tôi cũng sẽ thêm xml của mình. – bugzy
"Ở đâu hoặc làm thế nào để tôi chặn các chức năng để xử lý các lựa chọn" - bạn đã làm điều đó. Ở đâu đó, bạn đang gọi 'setText()' trên TextView. Chỉnh sửa mã đó. – CommonsWare
Đó là vấn đề ... Im không. Nó được xây dựng trong hành vi của các widget AutoCompleteTextView đó là populating phần TextView của widget AutoCompleteTextView. – bugzy