需要将数据从一个活动传递到另一个引用数据库

发布于 2024-12-02 07:23:52 字数 298 浏览 1 评论 0原文

在我的应用程序中,我想将一些字符串数据保存到数组中。

然后,该数据应该由 ListView 中的另一个活动获取。

我正在使用数据库来存储数据。但每次我都将数据存储在不同的表中。现在据我所知,不可能从定义的数据库中获取所有可用的表。

所以我想做的是,在创建表名时将其存储到Array 中。并将其显示在ListView中。

现在,当我按下特定的 ListIndex 时,它将获取该表的数据。

这可能吗?

In my application I want to save some string data into an array.

This data should then be fetched by the another activity in a ListView.

I am using a database to store the data. But every time I'm storing data in different tables. Now as per my knowledge it is not possible to fetch all the available tables from a defined database.

So what I'm trying to do is, store the table name into the Array while it is created. And displaying it in the ListView.

Now when I press on the perticular ListIndex, it will fetch the data of that table.

Is this possible?

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

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

发布评论

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

评论(1

旧情别恋 2024-12-09 07:23:52

使用表名称与数据数组的映射

    // Store
    Map<String, String[]> storage = new HashMap<String, String[]>();
    String[] items = {"one","two","three"}; // Your Data
    storage.put("tableName", items);        // Your table name

    // Retrieve a specific table
    String[] tableItems = storage.get("tableName");
    for(String s : tableItems){
        Log.i("TAG", "item name: "+s); // Will loop and print one , two then three
    }

    // Retrive all
    Set<String> allTables = storage.keySet();
    for (String table : allTables) {
        for(String s : storage.get(table)){
            Log.i("TAG", "table name: " + table + "item name: "+s);  // Will loop through each table, (we only have one) and print one , two then three
        }
    }

编辑

对于您关于发送表名称的评论:

    String[] items = {"tableOne","tableTwo","tableThree"}; // Your Data
    Intent intent = new Intent(this, Activity2.class);
    intent.putExtra("sendIntentTableName", items);
    startActivity(intent);

    ... onCreate(){
        String[] tableNames = getIntent().getStringArrayExtra("sendIntentTableName");
    }

Use a Map of Table Name against Array of Data

    // Store
    Map<String, String[]> storage = new HashMap<String, String[]>();
    String[] items = {"one","two","three"}; // Your Data
    storage.put("tableName", items);        // Your table name

    // Retrieve a specific table
    String[] tableItems = storage.get("tableName");
    for(String s : tableItems){
        Log.i("TAG", "item name: "+s); // Will loop and print one , two then three
    }

    // Retrive all
    Set<String> allTables = storage.keySet();
    for (String table : allTables) {
        for(String s : storage.get(table)){
            Log.i("TAG", "table name: " + table + "item name: "+s);  // Will loop through each table, (we only have one) and print one , two then three
        }
    }

EDIT

For your comment about sending table names:

    String[] items = {"tableOne","tableTwo","tableThree"}; // Your Data
    Intent intent = new Intent(this, Activity2.class);
    intent.putExtra("sendIntentTableName", items);
    startActivity(intent);

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