我有一個代碼,根據先前的佈局的EditText(ET)的值來改變佈局的TextView的文本>> somethig這樣做什麼,如果backpressed
我不能評論,所以我會幫助你編輯。使用SharedPreferences來存儲edittext中的字符串以獲得持久性。然後,您可以通過SharedPreferences字符串,做你正在做(將其穿過的意圖)
有MorningDrsGeneral同一件事:
public class MorningDrsGeneral extends ActionBarActivity {
Button button ;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.morningdrs);
et = (EditText) findViewById(R.id.et);
addListenerOnButton1();
}
public void addListenerOnButton1() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, bookingKamal.class);
intent.putExtra("fn" , et.getText().toString());
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
並有bookingKamal.java:
public class bookingKamal extends ActionBarActivity {
Button button;
TextView textView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bookingkamal);
textView3 = (TextView) findViewById(R.id.textView3);
String A = textView3.getText().toString();
String N = " ";
if (A.equals(N)){
Intent intent = getIntent();
String texx = intent.getStringExtra("fn");
textView3.setText(texx);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
所以我必須將文本保留在bookingKamal活動中。這意味着當我從此佈局返回時,文本應該與之前相同。而在此代碼回空:/或
它不是一個常數值。這是一個用戶輸入的值 你能告訴我怎麼做你說的嗎? –
查找意圖開始活動。您還應該從啓動此活動的活動中設置來自bookingKamal的變量。我想幫助你,但我不打算爲你寫完整的代碼。 – engineercoding