// 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 显示正确(“测试”)。上面的 Nr 3 完美地工作,EditText 有“测试”作为它的提示文本。
我首先尝试使用具有相同结果的字符串。明确使用 CharSequence 没有帮助。这是怎么回事???