Android 为什么我的上一个按钮没有';不行?
我提出了申请,但我的数据库又出现了问题。 我做了两个按钮——上一个按钮和下一个按钮。 “下一步”按钮是“工作”,但单击“上一步”按钮后,程序不会在文本视图中显示记录。为什么? 首先单击“嵌套”按钮“所有工作”,然后单击“上一步”按钮,“光标”转到上一条记录,但不在文本视图中显示该记录 我解决了我的问题。 我删除了方法:getNextdata()和getPrevData 现在我的代码是: Galeria.java:Android 为什么我的上一个按钮没有';不行?,android,sqlite,Android,Sqlite,我提出了申请,但我的数据库又出现了问题。 我做了两个按钮——上一个按钮和下一个按钮。 “下一步”按钮是“工作”,但单击“上一步”按钮后,程序不会在文本视图中显示记录。为什么? 首先单击“嵌套”按钮“所有工作”,然后单击“上一步”按钮,“光标”转到上一条记录,但不在文本视图中显示该记录 我解决了我的问题。 我删除了方法:getNextdata()和getPrevData 现在我的代码是: Galeria.java: public class Galeria extends Activity {
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;
}
我的所有按钮(下一个和前一个)都可以工作。谢谢您的帮助。在不运行代码的情况下,您确定没有忘记放置:
info.open()代码>
及
info.close()代码>
在上一个按钮的onclick侦听器中
例如:
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.getPrevData(record);
info.close();
tv.setText(data);
}
});
==================================
如果这不能解决问题,那么您的logcat是否指示任何错误?如果不是,您是否绝对确定正在从getPrevData(record)
方法检索字符串?您可以通过执行以下操作来检查这一点:
String data = info.getPrevData(record);
Log.d("bPoprzedni", data);
如果数据
没有显示在LogCat中,那么您就知道没有正确地从数据库中获取数据
如果数据
显示在LogCat中,那么您就缩小了问题范围,我们可以很容易地帮助您:)我添加了来自LogCat的消息。如果我在Android SDK 8中运行应用程序,上面的消息来自LogCat id。若我在SDK API 16级上运行应用程序,LogCat不会显示错误,但“上一步”按钮不起作用。@对不起,我不明白。修复(info.open()
和info.close()
)对于SDK API级别16仍然不起作用?它还在崩溃吗?即使在您输入了info.close()
?不,修复工作正常,我的按钮“bNastępny”(下一个)正常工作。我不知道为什么单击“上一步”按钮后,程序不显示数据库中以前的记录。我更新了我的问题。我的按钮现在可以用了。谢谢你的帮助。