// This is in the class which calls the next activity with an intent:
Bundle bundle = new Bundle();
bundle.putCharSequence("Hint", "test");
startActivityForResult(new Intent(this, PosAct.class)
.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
.putExtras(bundle)
, request_code);
// This is in the PosAct activity which is being called by the class above:
// 1 - Fails!
CharSequence temp = bundle.getCharSequence("Hint");
((EditText) findViewById(R.id.editTextFloor)).setHint(temp);
// 2 - Fails!
((EditText) findViewById(R.id.editTextRoom))
.setHint((CharSequence)bundle.getCharSequence("Hint"));
Toast.makeText(getApplicationContext(), bundle.getCharSequence("Hint"), Toast.LENGTH_LONG).show();
// 3 - Works perfectly!
((EditText) findViewById(R.id.editTextStreet)).setHint("test");
我尝试使用java代码而不是xml设置提示文本,但是我没有使用任何变量作为setHint()方法的参数。上面我尝试了3种不同的EditText。
上面的Nr 1不起作用。 EditText保持为空。 上面的Nr 2具有相同的结果,但Toast正确显示(“test”)。 上面的Nr 3完美地工作,EditText将“test”作为其提示文本。
我首先尝试使用具有相同结果的String。明确使用CharSequence没有帮助。这一切是什么???
答案 0 :(得分:1)
试试这个..
Intent intent = new Intent(this, PosAct.class)
.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
//load the intent with a key "hint" and assign it's value
//to be whatever has been entered into the text field...
intent.putExtra("hint","test");
在你的活动中,你要传递使用它..
Bundle extras = intent.getExtras();
mEditText1.setHint(extras != null ? extras.getString("hint"):"nothing