开发者

Creating a location book with Android

开发者 https://www.devze.com 2023-02-01 15:10 出处:网络
i\'m new to Android and i\'m developing an application who is supposed to show a list of places (the class extend activitylist) and when user choose a place it open a new activity with the place detai

i'm new to Android and i'm developing an application who is supposed to show a list of places (the class extend activitylist) and when user choose a place it open a new activity with the place details (name, address, phone开发者_运维问答 number, service..). Actually, i'm looking for a simple way to store those predefined locations details + a simple way to show them later on the app.


Actually, the best solution that i found is:

  1. Save a static file in your application at compile time, save the file in your project res/raw/ directory.

  2. Open the file with openRawResource(), passing the R.raw. resource ID. This method returns an InputStream that you can use to read the file (but you cannot write to the original file).

InputStream dataIS = getResources().openRawResource(R.raw.location);

  1. Convert input stream to buffered reader then you can store your data in a Sqlite3 table and use them wherever you want.
public void fillDB(){
        InputStreamReader in= new InputStreamReader(dataIS);
        BufferedReader dataBR= new BufferedReader(in);
        String dataLine;
        try {
        while ((dataLine = dataBR.readLine()) != null)   {
          // split the data line
          dataLineTokenizer = new StringTokenizer(dataLine, ":");
                //SQL query + save data to database
          String sql =  "INSERT INTO location ...";
          //execute query
          Log.v("Test Saving", sql);
          clubberDB.execSQL(sql);
        }
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }
0

精彩评论

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

关注公众号