1

AutoCompleteTextView を使用して、ユーザーが選択できる項目のリストを表示しています。ユーザーが項目を選択すると、この選択された項目が AutoCompleteTextView のすぐ下の ListView に表示されます。ここまでは順調ですね。

問題: AutoCompleteTextView から項目を選択した後、AutoCompleteTextView 本体自体 (この「テキスト ボックス」) は、SimpleCursorAdapter リソースであるテキストで埋められます (実際に表示されるテキストは android.widget. SimpleCursorAdapter@4107d010)。

私が望むもの: AutoCompleteTextView を更新して、それ自体の本文にテキストを表示しないようにして、ユーザーがすぐにテキストを入力して、ドロップダウン リストからさらに項目を選択できるようにします。

どうすればそれを達成できるか、ヒントを教えてください。

追加情報:

ありがとう、カイル。私がしたことは、SimpleCursorAdapter を SimpleCursorAdapterNoText に拡張することでした。次に、あなたが言ったように convertToString() をオーバーライドしました。ドキュメントを 2 回読んだので BindView を変更しませんでしたが、BindView で何を変更すればよいかまだわかりません。とにかく - これで問題は解決しませんでした - AutoComplete に同じ文字列が表示されます。これが私のコードです:

@SuppressWarnings("deprecation")
private void populateListView()
{
   // Get all of the notes from the database and create the item list
  Cursor tournamentXCursor = mDbHelper.retrieveTrounamentX(mRowId);
  startManagingCursor(tournamentXCursor);

  // Create an array to specify the fields we want to display in the list (only name)
  String[] from = new String[] {StournamentConstants.TblX.TBL_COLUMN_X_NAME};

  // and an array of the fields we want to bind those fields to (in this case just name)
  int[] to = new int[]{R.id.competitor_row};

  // Now create an array adapter and set it to display using our row
  SimpleCursorAdapterNoText tournamentX = new SimpleCursorAdapterNoText(this, R.layout.competitor_row, tournamentXCursor, from, to);

  tournamentX.convertToString(tournamentXCursor);
  setListAdapter(tournamentX);      
}

誰が私が間違っているのか手がかりを持っていますか?

編集: これは私の継承された SimpleCursorAdapter クラスです

 public class SimpleCursorAdapterNoText extends SimpleCursorAdapter 
{
    public SimpleCursorAdapterNoText(Context context, int layout, Cursor c,
        String[] from, int[] to) 
    {
        super(context, layout, c, from, to);
    // TODO Auto-generated constructor stub
    }

    @Override
    public CharSequence convertToString(Cursor cursor) 
    {
    //Empty string so AutoComplete shows no text
    return "";
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
    // TODO Auto-generated method stub
    super.bindView(view, context, cursor);
    }
}

呼び出しコードを変更して排除しました

tournamentX.convertToString(tournamentXCursor);

サブクラスでオーバーライドするだけでなく、呼び出しコードでも使用して、オートコンプリート内のテキストを削除することが不可欠であると確信しました。

これはまだ役に立たなかったと言ってサグしています.AutoComplete選択リストから1つのアイテムを選択した直後に、AutoCompleteBoxにandroid.database.sqlite.SQLiteCursor@41377578を取得し続けます。

ありがとう。

4

2 に答える 2

4

ユーザーがドロップダウン リストの項目をクリックしたときにテキストをクリアするだけの場合は、AutoComplete をメンバー変数として定義し、setOnItemClickListener をオーバーライドします。このような:

mAutoComplete.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        mAutoComplete.setText("");
    }
});
于 2012-05-04T21:49:19.970 に答える
0

simplecursoradapterを使用してtextViewを埋める場合は、それをサブクラス化し、次のメソッドをオーバーライドする必要があります。おそらく、bindviewもオーバーライドする必要があります。

@Override
public CharSequence convertToString (Cursor cursor){
   return "";
}

上記をSimpleCursorAdapterNoTextクラス内に配置する必要があり、トップレベルのコードから呼び出すのではありません。

class extends SimpeCursorAdpaterNotText{
// ... whatever other code you have here
@Override
    public CharSequence convertToString (Cursor cursor){
       return "";
    }
}
于 2012-04-30T22:48:56.300 に答える