【问题标题】:Casting issue while filtering using adapter, How to fix it?使用适配器过滤时出现投射问题,如何解决?
【发布时间】:2016-04-22 07:38:19
【问题描述】:

performFiltering()!期间发生异常

java.lang.ClassCastException: android.graphics.Bitmap 无法转换 到 java.lang.String

我的代码是这样的

adapter = new SimpleAdapter(
                    getActivity(), contactList,
                    R.layout.list_item, new String[]{TAG_USERNAME,TAG_Age,TAG_SPECIALITY,TAG_CITY,TAG_COUNTRY,TAG_IMAGE}, new int[]{R.id.USERNAME, R.id.AGE, R.id.SPECIALITY, R.id.City, R.id.Country, R.id.Image}
            );



   adapter.setViewBinder(new SimpleAdapter.ViewBinder() {

            @Override
            public boolean setViewValue(View view, Object data,
                                        String textRepresentation) {
                if ((view instanceof ImageView) & (data instanceof Bitmap)) {
                    ImageView iv = (ImageView) view;
                    Bitmap bm = (Bitmap) data;
                    iv.setImageBitmap(bm);
                    return true;
                }
                return false;
            }

        });

        setListAdapter(adapter);

        /**
         * Enabling Search Filter
         * */
        inputSearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                // When user changed the Text

                try {
                    if (adapter != null) {
                        ChefFragment.this.adapter.getFilter().filter(cs);
                    } else {
                        Log.d("filter", "no filter availible");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                                          int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void afterTextChanged(Editable arg0) {
                // TODO Auto-generated method stub
            }
        });

【问题讨论】:

    标签: android textwatcher simpleadapter


    【解决方案1】:

    我假设您在比较器中将搜索字符串与位图图像进行比较,这是不可能的。

    【讨论】:

    • ok.. 如何使用 SimpleAdapter 过滤列表视图上的图像?
    猜你喜欢
    • 2016-07-08
    • 1970-01-01
    • 2019-10-29
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-16
    相关资源
    最近更新 更多