从 SimpleCursorAdapter 获取位置

发布于 2024-12-01 04:39:46 字数 691 浏览 4 评论 0原文

有办法做到这一点吗?我的具体目的是尝试从列表中的编辑文本填充标签,该列表由简单光标适配器填充。当我从光标收集信息时,仅给出列表中最新项目的值。

示例:

        lbs = (TextView)view.findViewById(R.id.GrainLbs);
    lbs.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent arg1) {
            if(!popState){
                parentActivity.showPopup(v, mView, getId, String.valueOf(getLbs));
                Log.i("Current ID", "");
            }
            setPopState();
            return true;
        }   
    });

我试图从自定义 simplecursoradapter (String.valueOf(getLbs)) 中将数据库中的值传递到活动中的方法,因为我通过单击列表视图中的对象来收集此信息,我认为它将自动使用特定列表项中的数据。有没有办法获取列表项位置,然后根据该位置使用数据库中的信息?

Is there a way to do this? My specific purpose is that I am trying to populate a label from an edittext within my list that is populated by a simplecursoradapter. When I gather the information from the cursor is only gives me the value from the most recent item in the list.

Example:

        lbs = (TextView)view.findViewById(R.id.GrainLbs);
    lbs.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent arg1) {
            if(!popState){
                parentActivity.showPopup(v, mView, getId, String.valueOf(getLbs));
                Log.i("Current ID", "");
            }
            setPopState();
            return true;
        }   
    });

I'm trying to pass the value from the database to a method in my activity from within my custom simplecursoradapter (String.valueOf(getLbs)) which since i'm gathering this information by clicking on an object in the listview I thought it would automatically use the data from the specific list item. Is there a way I can get the list item position and then use info from the database based on the position?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜巴黎 2024-12-08 04:39:46

如果您要扩展 ListActivity,则可以覆盖 ListActivity.onListItemClick。传递到该函数的第二个参数是列表中的位置,它与 SimpleCursorAdapter 中的位置相同。

If you are extending ListActivity, then you can override ListActivity.onListItemClick. The second argument passed into that function is the position in the list, which is the same as the position in your SimpleCursorAdapter.

终陌 2024-12-08 04:39:46

事实证明这是一个如此简单的答案,我不敢相信我花了这么多时间试图弄清楚它。因为我正在收集内部方法(onclicklistener)中的值,所以我需要将变量设为最终变量,它是在类的开头声明的,因此可以在整个过程中使用它,因此我没有收到异常,但无论出于何种原因,我都需要将其确定为最终值,然后才能传递正确的值。

所以我想如果您将视图绑定在自定义游标适配器中,您可以在不知道位置的情况下收集每个单独列表项的值,它会自动为您知道这一点。

This turned out to be such a simple answer and I can't believe i've spent so much time trying to figure it out. Because I was collecting the value within an inside method (an onclicklistener) I needed to make my variable final, it was declared at the beginning of the class so it could be used throughout, and because of this I wasn't getting an exception, but I needed to make it final before it would pass the correct value for whatever reason.

So I guess if you bind your views within a customcursoradapter you can collect values for each individual listitem without knowing the position, it automatically knows this for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文