我需要帮助理解 putExtra 和检索行 id 吗?
早上好,我很乐意帮助您解决我的特定代码,但如果您很忙,任何有关使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这是否有帮助。我认为我的实现与您的略有不同,但功能相似。
See if this helps. I think my implementation is slightly different from your, but is for a similar function.