我需要帮助理解 putExtra 和检索行 id 吗?

发布于 2024-10-07 02:15:02 字数 1412 浏览 4 评论 0原文

早上好,我很乐意帮助您解决我的特定代码,但如果您很忙,任何有关使用 putExtra 和retrieveRow 的信息也会有很大帮助。

我正在开发一个小型 Android 项目,并且我已经遇到我需要将数据从一个活动传递到另一个活动的第一个实例,不幸的是我缺乏知识。我尝试查看 android 记事本示例,但我很困惑,所以我希望有人可以使用我自己的代码向我解释。

这就是我想要做的..我有一个 onItemClick 侦听器,用于从 sqlite 数据库填充的列表视图,当选择它时,我想传递行 _id 以及该行的另一列的内容(BUDGET_AMOUNT )到另一个班级。所以我认为我需要像下面这样的东西,但正如你从所有问号中看到的那样,我真的很困惑如何实现我需要的东西。

// add an onclicklistener for when an item on the list is pressed
        incomeView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                {
                Cursor c = ???.retrieveRow(id);

                Intent keypadIntent = new Intent(view.getContext(), Keypad.class);
                keypadIntent.putExtra(???._ID, id);//put extra needs work
                keypadIntent.putExtra(???.BUDGET_AMOUNT, c.getFloat(
                        c.getColumnIndexOrThrow(???.BUDGET_AMOUNT)));
                startActivityForResult (keypadIntent, ???);


                }
            });

上面的代码来自我的 Budget.java 类,我已将其上传到此处。我还有一个名为 Data.java 的类,它扩展了 SQLiteOpenHelper 和一个名为 DatabaseConstants 它只有一大堆用于类别和查询的字符串变量。感谢您花时间查看或提供建议。

Morning, I would love help with my specific code but if you're busy any information on using putExtra and retrieveRow would also be a great help.

I'm working on a little android project and i've come across the first instance where i need to pass data from one activity to another, unfortunately my knowlede is lacking. I've tried looking at the android notepad example but i'm getting pretty mixed up so i'm hoping someone can explain to me using my own code.

Here's what i'm trying to do.. I have an onItemClick listener for a listview i've populated from a sqlite database, when it's selected i want to pass the row _id along with the contents of another column for that row (the BUDGET_AMOUNT) to another class. So I think i need something like below but as you can see by all the questionmarks i'm really confused about how to implement what i need.

// add an onclicklistener for when an item on the list is pressed
        incomeView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                {
                Cursor c = ???.retrieveRow(id);

                Intent keypadIntent = new Intent(view.getContext(), Keypad.class);
                keypadIntent.putExtra(???._ID, id);//put extra needs work
                keypadIntent.putExtra(???.BUDGET_AMOUNT, c.getFloat(
                        c.getColumnIndexOrThrow(???.BUDGET_AMOUNT)));
                startActivityForResult (keypadIntent, ???);


                }
            });

The code above is from my Budget.java class, which i've uploaded here. I also have a class called Data.java which extends SQLiteOpenHelper and a class called DatabaseConstants which just has a whole bunch of string variables for categories and queries. Thanks for taking the time to have a look or offer advice.

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

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

发布评论

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

评论(1

垂暮老矣 2024-10-14 02:15:02

看看这是否有帮助。我认为我的实现与您的略有不同,但功能相似。

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    // Get the item that was clicked

    Intent selectedProjectType = new Intent();

    Cursor o = (Cursor) this.getListAdapter().getItem(position);
    String keyword = o.getString(1);

    selectedProjectType.putExtra("selectedprojecttype", keyword);

    setResult(RESULT_OK, selectedProjectType);
    finish();
}

See if this helps. I think my implementation is slightly different from your, but is for a similar function.

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    // Get the item that was clicked

    Intent selectedProjectType = new Intent();

    Cursor o = (Cursor) this.getListAdapter().getItem(position);
    String keyword = o.getString(1);

    selectedProjectType.putExtra("selectedprojecttype", keyword);

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