我开始从事 Android 开发,我需要关闭一个setContentView()
调用,onClickListener()
其中myCurrent
屏幕是一个比其他布局膨胀的布局。
这是我的代码:
public class MainActivity extends Activity {
private SQLiteDatabase myDb;
private String dbPath = "/data/data/com.example.dbapp/databases/testData";
private boolean dbExist(String dbPath){
File fakeDb = new File(dbPath);
return fakeDb.exists();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(!dbExist(dbPath)){
myDb = openOrCreateDatabase(dbPath, MODE_PRIVATE, null);
myDb.execSQL("CREATE TABLE files(cn_userName INTEGER PRIMARY KEY AUTOINCREMENT);");
myDb.close();
}else{
fillDb();
}
}
private void fillDb(){
LinearLayout myScroll = (LinearLayout) findViewById(R.id.idOfmyScroll);
if(myScroll.getChildCount() > 0){
myScroll.removeAllViews();
}
myDb = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READONLY);
Cursor myDbCur = myDb.rawQuery("SELECT * FROM files", null);
for(int i = 0; i < myDbCur.getCount(); i++){
View name = getLayoutInflater().inflate(R.layout.name_list, null);
TextView userName = (TextView)name.findViewById(R.id.idName);
userName.setText(myDbCur.getString(myDbCur.getColumnIndex("cn_userName"));
myScroll.addView(name);
myDbCur.moveToNext();
myDb.close();
name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.otherUserData);
userLastName = (TextView)findViewById(R.id.txtLastName);
nombreContacto.setText(userName + "Her LastName");
}
});
}
}
当我按后退键跳转到 activity_main 并且我想要膨胀的布局