我有一个代码,根据先前的布局的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