EditText を Activity1 から Activity2 に渡そうとしています。
アクティビティ 1 コード:
public void openNextActivity()
{
Intent intent = new Intent("com.abc.xyz.ImageActivity");
EditText myEditText = (EditText)findViewById(R.id.myEditText);
int myEditTextId = myEditText.getId();
//For Test purpose ----- starts
// **Point1: next line of code works fine in this Activity1**
EditText myEditTextTest = (EditText)findViewById(myEditTextId);
//For Test purpose ----- ends
intent.putExtra("myEditText", myEditTextId);
startActivity(intent);
}
アクティビティ 2 コード:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.comments_detail);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
int myEditTextId = extras.getInt("myEditText");
// Point2: next line of code displays the correct Id
Log.d("tag","myEditTextId"+ myEditTextId);
// Point 3: Next line of code not works in this Activity2
EditText myEditText = (EditText)findViewById(myEditTextId);
if(myEditText != null)
{
Log.d("tag","Not null");
}
else
{
Log.d("tag","null");// **Point4: this condition executes**
}
}
}
問題は次の行です: EditText myEditText = (EditText)findViewById(myEditTextId); Activity1 では正常に動作します が、Activity2 では動作しません。
編集:
注:両方のアクティビティで異なるレイアウトが使用されています。貴重なお時間とご協力をいただきありがとうございます。