I am setting my textview using columns from a sqlite database file.Problem is that when i change the view back and forth, there is a very obvious lag while it retrieves from the database.Here is the code:
public class Flipcard extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layMain = (LinearLayout) findViewById(R.id.FlashCardFront);
layMain.setOnClickListener(this);
Cursor cur;
DbH db = null;
TextView tv=(TextView) findViewById(R.id.TV_Word);
TextView txtView=(TextView) findViewById(R.id.TV_CardNo);
try {
db=new DbH(this);
} catch (IOException e2) {
e2.printStackTrace();
}
try {
db.createdatabase();
} catch (IOException e) {
e.printStackTrace();
}
db.opendatabase();
cur=db.data();
cur.moveToFirst();
tv.setText(cur.getString(0));
cur.close();
}
public void onClick(View v) {
Intent i=new Intent(this,Flipcard_back.class);
startActivity(i);
}
}
the other java file that is being called on click is:
public class Flipcard_back extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_back);
LinearLayout layMain = (LinearLayout) findViewById(R.id.FlashCardRear);
layMain.setOnClickListener(this);
}
public void onClick(View v) {
Intent i=new Intent(this,Flipcard.class);
startActivity(i);
}
}
which is actually calling previous one.The problem is i'm one a very initial phase on my app development.Right now i am only trying to change two textviews in first java file using my database.When i switch back and forth there is a lag of around a second.How do i correct it? am i doing something wrong. Also i am not able to retrieve all the rows using getstring(1) etc.Why so?How do i get the columns one by one?