アプリケーションを作成しましたが、データベースに再び問題があります。前のボタンと次のボタンの2つのボタンを作成しました。次のボタンは機能しますが、前のボタンをクリックした後、プログラムはテキストビューでレコードを表示しません。なんで?最初にネストボタンをクリックしてすべての作業を行い、次に前のボタンをクリックして「カーソル」をクリックすると前のレコードに移動しますが、テキストビューにレコードが表示されません。
私は自分の問題を解決しました。getNextdata()とgetPrevDataのメソッドを削除しました。
今私のコードは次のとおりです。
Galeria.java:
public class Galeria extends Activity {
public static long record = 1;
PrzyslowiaArabskie info = new PrzyslowiaArabskie(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.galeria);
TextView tv = (TextView) findViewById(R.id.editText1);
info.open();
int irec = info.policz_rec();
Toast.makeText(getApplicationContext(), " ilość przysłów w bazie " + irec, Toast.LENGTH_SHORT).show();
String data = info.getData(record);
info.close();
tv.setText(data);
Button bNastepny = (Button) findViewById(R.id.next);
bNastepny.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv = (TextView) findViewById(R.id.editText1);
info.open();
record++;
String data = info.getData(record);
info.close();
tv.setText(data);
}
});
Button bPoprzedni = (Button) findViewById(R.id.prev);
bPoprzedni.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv = (TextView) findViewById(R.id.editText1);
info.open();
record--;
String data = info.getData(record);
info.close();
tv.setText(data);
}
});
}
}
DB Helperクラスの私のメソッド:
public String getData(long record) {
// TODO Auto-generated method stub
record = Galeria.record;
String[] columns = new String[] { KEY_ID, KEY_PRZYSLOWIE};
Cursor c = myDatabase.query(TABLE_NAME, columns, KEY_ID + "=" + record, null, null, null, null);
if (c != null) {
c.moveToFirst();
String data = c.getString(1);
return data;
}
return null;
}
そして、私のすべてのボタン(次のボタンと前のボタン)が機能します。助けてくれてありがとう。