我通过查看 sqlite 数据库中的报价来创建应用程序。当我单击下一个按钮时,每个报价显示在一个页面中,它移动到下一个报价,在最后一个报价中,当我按下上一个按钮时,它移动到第一个报价,我想移到上一个报价
public class ResultsActivity extends Activity implements OnClickListener{
private DuasDatasource dbHelper;
SharedPreferences sp;
Button btnPrevious,btnNext,btnHome,btnIndex;
final Context ctx=this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultsinfo);
dbHelper = new DuasDatasource(this);
dbHelper.open();
btnPrevious= (Button) findViewById(R.id.btnPrevious);
btnPrevious.setOnClickListener(this);
btnNext = (Button) findViewById(R.id.btnNext);
btnNext.setOnClickListener(this);
btnIndex = (Button) findViewById(R.id.btnIndex);
btnIndex.setOnClickListener(this);
btnHome = (Button) findViewById(R.id.btnHome);
btnHome.setOnClickListener(this);
displayListView();
}
private void displayListView() {
Bundle extras = getIntent().getExtras();
String value = null;
if (extras != null) {
value = extras.getString("dua_id");
}
Cursor cur = dbHelper.fetchById(value);
displayData(cur);
setBtnVisible();
}
`private void setBtnVisible(){
Bundle extras = getIntent().getExtras();
String value = null;
Cursor cursor = dbHelper.fetchAll();
int curCount=cursor.getCount();
if (extras != null) {
value = extras.getString("dua_id");
}
if(Integer.parseInt(value)==1){
btnPrevious.setVisibility(View.GONE);
btnNext.setVisibility(View.VISIBLE);
}else if(Integer.parseInt(value)>1 && Integer.parseInt(value)<curCount){
btnPrevious.setVisibility(View.VISIBLE);
btnNext.setVisibility(View.VISIBLE);
}
else if(Integer.parseInt(value)==curCount){
btnNext.setVisibility(View.GONE);
btnPrevious.setVisibility(View.VISIBLE);
}
}`