当我按下“后退”按钮时如何返回上一个布局 我创建了一个活动,当我按下按钮时,它将创建列表视图setcontentview,但是当我在列表视图页面中按返回按钮时,它不会返回到RecomPage布局
```
public class RecomPage extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recom_page);
dis.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RecomPage.this.onPause();
if (sp1.getSelectedItem().equals("ภาคเหนือ")) {
Toast.makeText(getApplicationContext(), "กรุณาเลือกจังหวัดของพื้นที่นา", Toast.LENGTH_LONG).show();
}
else if (cb3.isChecked() && !cbres.isChecked() && !cb2.isChecked()) {
//Select * FROM RiceRec WHERE N = 1 AND Solid_Sandy = 1 AND Nope = 1
setContentView(R.layout.listview_product);
lvProduct = (ListView) findViewById(R.id.listview_product);
mDBHelper = new DBHelper(RecomPage.this);
//return productList;
File database = getApplicationContext().getDatabasePath(DBHelper.DBNAME);
if (false == database.exists()) {
mDBHelper.getReadableDatabase();
//Copy db
if (copyDatabase(RecomPage.this)) {
Toast.makeText(RecomPage.this, "Copy database succes", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(RecomPage.this, "Copy data error", Toast.LENGTH_SHORT).show();
return;
}
}
//Get product list in db when db exists
mRiceList = mDBHelper.getListRice35();
//Init adapter
adapter = new RiceAdapter(RecomPage.this, mRiceList);
//Set adapter for listview
lvProduct.setAdapter(adapter);
}
}
lvProduct.setOnItemClickListener(new AdapterView.OnItemClickListener() {
......................................................
});
}
}
private boolean copyDatabase(Context context) {
...................
}
}
);
}
}
我尝试使用此
public void onBackPressed(){
Intent intent = new Intent(this, RecomPage.class);
startActivity(intent);
}
返回到RecomPage布局,但它一直显示此内容,并且无法进行其他活动