0

listView で製品名を検索したいのですが、検索テキスト フィールド内にテキストを入力してもリスト内に何も表示されません。私は ArrayAdapter を使用していませんが、ResourceCursorAdapter を使用しています。

   public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                helper = new ComicsData(this);
                helper.open();
                listSearch=(EditText)findViewById(R.id.inputSearch);
                listSearch.addTextChangedListener(filterTextWatcher);
                model = helper.getAllProduct(list);
                startManagingCursor(model);
                adapter=new ShoppingListAdapter(this, model);

                listView.setAdapter(adapter);
    }
private TextWatcher filterTextWatcher=new TextWatcher(){

         public void afterTextChanged(Editable s) {

            }

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                //String search=listSearch.getText().toString();
                //int textLength=search.length();
                adapter.getFilter().filter(s);

            }

        };

ShoppingListAdapter

class ShoppingListAdapter extends ResourceCursorAdapter {

        private final String CN = null;

        public ShoppingListAdapter(Context context, Cursor c) {
            super(context, R.layout.productrow, c);
            // TODO Auto-generated constructor stub
        }
    @Override
        public void bindView(View row, Context context, Cursor c) {
            // TODO Auto-generated method stub


            listName = (TextView) row.findViewById(R.id.produtName);
    listName.setText(helper.getProductName(c));

誰も私の間違いを知っていますか?

4

2 に答える 2

1

listSearch のテキストを変更した後、検索テキストに従ってアイテムを取得しhelper.getProducts(searchText);、呼び出しますadapter.notifyDataSetChanged()

于 2012-12-07T13:40:20.343 に答える
0

アダプターにFilterQueryProviderのインスタンスを提供する必要があります。このプロバイダーはフィルター クエリを取得し、見つかったすべてのアイテムを含むカーソルを返します。

于 2012-12-07T13:46:49.717 に答える