简体   繁体   中英

Android: Build an array from data in another file

If I have an activity, and I want that activity to get data from a stub file within the project and put it into an array, how would I do this?

At the moment I've used data which is hard coded into the activity using a setListAdapter making a new ArrayAdapter with the following building this array:

    static final String[] Food = new String[] {

        "Chips", "Fish"

    };

I think this tutorial should help you. It reads a file line by line and prints the content on the console. Instead of printing the content on the console, you should just add it to your array.

For example the line:

System.out.println(dis.readLine());

Could look like this:

food[0] = dis.readLine();

Btw... variable names in Java shouldn't be uppercase (Java Naming Convetions).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM