我制作了应用程序,但我又遇到了数据库问题。我做了两个按钮——上一个按钮和下一个按钮。下一个按钮可以工作,但是单击上一个按钮后,程序不会在 textview 中显示记录。为什么?首先我单击嵌套按钮所有工作然后我单击上一个按钮和“光标”转到上一个记录但不在文本视图中显示记录。
我解决了我的问题。我删除了方法: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;
}
我的所有按钮(下一个和前一个)都可以工作。谢谢你的帮助。