开发者

Need to pass data from one activity to another referencing database

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 o开发者_JAVA技巧n the perticular ListIndex, it will fetch the data of that table.

Is this possible?


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");
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜