-5

I am making an app that my wife can use to check if a certain IC friendly or not. The problem is that I need 5 columns if you will (foodName, safe, try, avoid, foodCategory. Each may or may not have a description of the food name under safe, try, avoid. Should I use a database an .xls file or can I do it in xml?

Tushar Gogna
  • 4,963
  • 6
  • 31
  • 42

3 Answers3

2

It depends on your requirement/ useage

use sharedPreferences or sqlite database

if you want to store data for long term use sqlite

and if you want to maintain sessions use SharedPreferences.

SharedPreference

SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE).edit();
 editor.putString("name", "Elena");
 editor.putInt("idName", 12);
 editor.commit();

Retrieve data from preference:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String restoredText = prefs.getString("text", null);
if (restoredText != null) {
  String name = prefs.getString("name", "No name defined");//"No name defined" is the default value.
  int idName = prefs.getInt("idName", 0); //0 is the default value. and it requires API 11
}

And for using Sqlite @Sri Hari have shown you an example..

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • sharedPreferences can not do task in his case. He is trying to store multiple rows (of 5 columns). So how can he do it? – Pankaj Kumar Aug 19 '14 at 11:56
  • @PankajKumar he know edited his question . I have answered it according to the previous question he has asked – Zar E Ahmer Aug 19 '14 at 12:08
0

For storing data in android you can use:

  • Shared Preferences - Store private primitive data in key-value pairs
  • Internal Storage - Store private data on the device memory
  • External Storage - Store public data on the shared external storage
  • SQLite Databases - Store structured data in a private database
  • Network Connection - Store data on the web with your own network server.

IMO for your purposes the most efficient option can be Shared Prefeerences or SQLite Database

More details for storing data you can find here.

Please note that you can look also for some ORMs to make it easier with SQLite Database - GreenDAO, OrmLite,...

Robert
  • 1,272
  • 4
  • 21
  • 40
0

Create a new SQLite database and store it. her you can store multiple tables safely.

public class DictionaryOpenHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 2;
private static final String DICTIONARY_TABLE_NAME = "dictionary";
private static final String DICTIONARY_TABLE_CREATE =
            "CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +
            KEY_WORD + " TEXT, " +
            KEY_DEFINITION + " TEXT);";

DictionaryOpenHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(DICTIONARY_TABLE_CREATE);
}
}
Srihari
  • 2,387
  • 9
  • 51
  • 82
  • This is the way I want to do it but how do I access the database that I created and where do I import it to in my application? – Mike Stratmann Aug 19 '14 at 14:34
  • Read this article `http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/` using `cursor` we can access data from SQLite. – Srihari Aug 21 '14 at 07:28