ListView数据解析和导航

发布于 2024-11-01 02:29:36 字数 484 浏览 1 评论 0原文

我有物品清单。该项目在数据库中具有与其相关的详细信息。我想单击列表中的一个项目,然后导航到一个活动,该活动在 EditText 中显示该项目的详细信息。我已经有了导航部分,但我无法执行最重要的部分,即显示我单击的项目的详细信息。

这是我的导航方法

edition.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            final String aux= (String) lt.getItemAtPosition(position);
            Intent myIntent = new Intent(infoList.this, EditarLocais.class);
            startActivity(myIntent);
        }
    });

有人可以帮忙吗?

谢谢

I have list of items. This items have details associated with them, in the database. I want to click on a item of the list and that navigate to a activity that shows the details of this items in a EditText. I already have the navigation part but i can't do the most important part that consist in show the details of the item i clicked.

this is my method for navigation

edition.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            final String aux= (String) lt.getItemAtPosition(position);
            Intent myIntent = new Intent(infoList.this, EditarLocais.class);
            startActivity(myIntent);
        }
    });

Can somebody help?

thanks

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

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

发布评论

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

评论(2

国粹 2024-11-08 02:29:36

以“Android Way”执行此操作,

然后在 ItemActivity 中使用 ContentProvider

public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Intent itemIntent = new Intent(this, ItemActivity.class);
    listIntent.setData(Uri.withAppendedPath("content://my.app.content/edition", Long.toString(id)));
    startActivity(listIntent);
}

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item_activity);
    Intent intent = getIntent();
    if (intent != null) {
        Uri uri = intent.getData();
        if (uri != null) {
            Cursor cursor = managedQuery(uri, new String[] { "All", "Columns", "That" }, null, null, null);

do it in "Android Way"

use ContentProvider

public void onItemClick(AdapterView<?> l, View v, int position, long id) {
    Intent itemIntent = new Intent(this, ItemActivity.class);
    listIntent.setData(Uri.withAppendedPath("content://my.app.content/edition", Long.toString(id)));
    startActivity(listIntent);
}

then in ItemActivity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item_activity);
    Intent intent = getIntent();
    if (intent != null) {
        Uri uri = intent.getData();
        if (uri != null) {
            Cursor cursor = managedQuery(uri, new String[] { "All", "Columns", "That" }, null, null, null);
帅哥哥的热头脑 2024-11-08 02:29:36

选项#1:

Application 类可能就是您正在寻找的。有一个很好的答案解释了如何使用它,实际上它就是您需要的一切。您可以在这里找到答案: Android:如何声明全局变量?

选项 #2:

使用 Intent.putExtra(...) 方法将更多数据从上一个 Activity 发送到下一个 Activity

选项#3:

这是一个肮脏的快速修复(不推荐)。将您的数据对象声明为static,并使用YourActivity.mMyDataObject 访问它。

Option #1:

The Application class could be what you're looking for. There is a very good answer that explains how to use it and actually it is everything you need. You can find the answer here: Android: How to declare global variables?.

Option #2:

Use Intent.putExtra(...) method to send further data from your previous Activity to your next Activity.

Option #3:

This is a dirty quick fix (not recommended). Declare your data object as static and reach it by using YourActivity.mMyDataObject.

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