Create Location Book with Android

I am new to Android, and I am developing an application that should show a list of places (the class expands the activity list), and when the user selects a place where he opens a new action with information about the place (name, address, phone number, service ..). In fact, I'm looking for an easy way to store this predefined location data + an easy way to show it later in the application.

+4
source share
1 answer

Actually, the best solution I found is:

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

  • Open the file with openRawResource () by passing R.raw. resource identifier. This method returns an InputStream, which you can use to read the file (but you cannot write it to the source file).

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

  • Converting the input stream into a buffered reader, then you can store your data in the Sqlite3 table and use it 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
source

Source: https://habr.com/ru/post/1333262/


All Articles