i have 2460 rows to insert in my sqlite DB by a click, my question : there's any way to improve this code to be more efficient and get better performance ?
is keeping DBHelper is good in this situation, having that i need to show my data in a Listview with a lot of queries ?
what do you think ?
Thank you, and sorry for my english
My class:
public class MainActivity <ButtonListener> extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnSimple = (Button) findViewById(R.id.buttonviewrec1);
btnSimple.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent (v.getContext(),ViewTeam.class);
startActivityForResult(intent, 0);
}
});
Button btnasearch = (Button) findViewById(R.id.searchbtn1);
btnasearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String tmname1= "spurs";
String tmopponent1= "lal";
String tmdate1= "26/12/2014 12:00";
String tmname2= "Maavs";
String tmopponent2= "Raps";
String tmdate2= "22/12/2014 03:30";
String tmname3= "Clips";
String tmopponent3= "Bulls";
String tmdate3= "19/12/2014 01:30";
TeamModel pm;
DBHelper db;
db = new DBHelper(getApplicationContext());
db.getWritableDatabase();
pm = new TeamModel();
pm.teamname=tmname1;
pm.teamopponent=tmopponent1;
pm.teamdate=tmdate1;
Log.i("teamname,teamopponent,teamdate", "" + pm.teamname + ""
+ pm.teamopponent + "" + pm.teamdate);
db.addTeam(pm);
pm.teamname=tmname2;
pm.teamopponent=tmopponent2;
pm.teamdate=tmdate2;
Log.i("teamname,teamopponent,teamdate", "" + pm.teamname + ""
+ pm.teamopponent + "" + pm.teamdate);
db.addTeam(pm);
pm.teamname=tmname3;
pm.teamopponent=tmopponent3;
pm.teamdate=tmdate3;
Log.i("teamname,teamopponent,teamdate", "" + pm.teamname + ""
+ pm.teamopponent + "" + pm.teamdate);
db.addTeam(pm);
}
});
}
My DBHelper
public class DBHelper extends SQLiteOpenHelper{
public DBHelper(Context context) {
super(context, DATABASENAME, null, 33);
c = context;
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE if not exists teamstable(id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "teamname"
+ " TEXT,"
+ "teamopponent"
+ " TEXT,"
+ "teamdate" + " TEXT)");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS" + teamstable);
onCreate(db);
}
//Add record
public void addTeam(TeamModel teamitem) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("teamname", teamitem.teamname);
contentValues.put("teamopponent", teamitem.teamopponent);
contentValues.put("teamdate", teamitem.teamdate);
db.insert("teamstable", null, contentValues);
db.close();
}
My TeamModel Class
public class TeamModel {
public String teamname="", teamopponent="", teamdate="";
public String getTeamname() {
return teamname;
}
public void setTeamname(String teamname) {
this.teamname = teamname;
}
public String getTeamopponent() {
return teamopponent;
}
public void setTeamopponent(String teamopponent) {
this.teamopponent = teamopponent;
}
public String getTeamdate() {
return teamdate;
}
public void setTeamdate(String teamdate) {
this.teamdate = teamdate;
} }