微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SimpleCursorAdapter未定义?

如何解决SimpleCursorAdapter未定义?

| 以下是使我感到悲伤的代码示例。如果我将它放置在textchangedlistener之外,则simpleCursorAdapter可以工作,但不能继续工作   构造函数SimpleCursorAdapter(new TextWatcher(){},int,Cursor,String,int,null)是未定义的
txt.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s,int start,int before,int count) {
                //onTextChanged
            }

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

            }

            public void afterTextChanged(Editable s) {
                //afterTextChanged
                typedText = s.toString();

                Cursor cur = db.rawQuery(\"SELECT * FROM \" +
                        DB_TABLE +\" where field LIKE \'%\" + typedText + \"%\'\",null);
                String displayFields = \"field\";
                int displayViews = R.id.bmark_visits;
                setlistadapter(new SimpleCursorAdapter(this,R.layout.testlist,cur,displayFields,displayViews,null
                ));
            }
        });
    

解决方法

        
SimpleCursorAdapter
构造函数的第一个参数应该是您的活动。但是,在匿名
TextWatcher
内部类中,
this
是匿名TextWatcher内部类的实例。请改用
MyActivity.this
,其中
MyActivity
是活动的名称。     ,        您应该调用活动的管理游标方法。否则,它们会泄漏出去。
activity.startManagingCursor( cursor );
斯特凡     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。