私は2つのxmlを持っています。名前はformOne.xmlとformTwo.xmlです
formOne.xml は次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
および fomTwo.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:id="@+id/buttonSave"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="@string/btSave" />
</LinearLayout>
名前は FormOne.java と FormTwo.java です。
FormOne.java :
public class FormOne extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.formOne);
EditText etName = (EditText) findViewById(R.id.editTextName);
}
}
および FormTwo.java :
public class FormTwo extends Activity implements OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.formTwo);
EditText etName = (EditText) findViewById(R.id.editTextName);
Button btSave = (Button) findViewById(R.id.buttonSave);
btSimpan.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (etName.getText().length() != 0) {
Toast.makeText(FormTwo.this, "Name is : "+etName.getText().toString(), Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(FormTwo.this, "Input the name please", Toast.LENGTH_SHORT).show();
}
// TODO Auto-generated method stub
}
});
}
editTextName から値を取得したいのですが、Toast を使用して FormTwo.java に値を表示できます。
しかし、myapplicationは強制的に閉じます。バンドルでデータを渡さずに値editTextNameを取得するにはどうすればよいですか。FormOne.java には値 editTextName を送信するボタンがないためです。
前もって感謝します