// 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");
xml の代わりに Java コードを使用してヒント テキストを設定しようとしましたが、setHint() メソッドの引数として変数を使用できませんでした。上記では、3 つの異なる EditText で試行を行います。
上記の番号 1 は機能しません。EditText は空のままです。上記の 2 番目の結果は同じですが、トーストは正しく表示されます (「テスト」)。上記の番号 3 は完全に機能します。EditText にはヒント テキストとして「test」があります。
最初に String を使用して同じ結果を試しました。CharSequence を明示的に使用しても役に立ちませんでした。これは何ですか?