0

I want to populate my DB for an android app, but I don't know if I am doing well. So I would like to ask for little help here

here is my code for DB

public long createData() {
    // TODO Auto-generated method stub
    String [] arg = new String [] {"Abdullah", "Abdulatif","Abdulaziz","Abdulbaki","Zafir"};
    String [] mng = new String [] { "Adhurues; Rob i Zotit", "Adhurues i Zotit Ledhatues","Adhurues i Zotit Fuqiplotë","Adhurues i Zotit të përhershëm","Fitimtar"};
    String [] gnr = new String [] {"Mashkull", "Mashkull","Mashkull", "Mashkull", "Mashkull"};
    ContentValues cv = new ContentValues();
    for (int i = 0; i < arg.length; i++){
        cv.put(KEY_EMRI, arg[i]);

        cv.put(KEY_KUPTIMI, mng[i]);


        cv.put(KEY_GJINIA, gnr[i]);
        ourDatabase.insert(DATABASE_TABLE, null, cv);
    }
    return  ourDatabase.insert(DATABASE_TABLE, null, cv);

} 

and here is my method onCreate in java file which I want to show the resuld from DB

    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.meshkuj);

    search = (Button) findViewById(R.id.bKerko);
    etSearch = (EditText) findViewById(R.id.etKerko);
    tvName = (TextView) findViewById(R.id.tvEmr);
    tvGenre = (TextView) findViewById(R.id.tvGjinia);
    tvMeaning = (TextView) findViewById(R.id.tvKuptimi);
    emri = (TextView) findViewById(R.id.tvShEmri);


    Emertimet info = new Emertimet(this);
    info.open();
    info.createData();
    info.close();           
}

So again I just want to know any other method to populate DB or (createData) or this method is good. THank you in advance

Hariss
  • 273
  • 1
  • 2
  • 10

1 Answers1

0

You are doing it wrong because

  1. you are doing it on main thread ( fragments here: Correct use of Sqlite on Android (SQLiteOpenHelper, connections, main thread, etc...) )
  2. you are not batching it in transaction ( Android SQLite database: slow insertion )
Community
  • 1
  • 1
MaciejGórski
  • 22,187
  • 7
  • 70
  • 94