Salve,
codice:
Vorrei aprire una nuova finestra(classe Form) attraverso un bottone
public class MainActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.form_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// your handler code here
setContentView(R.layout.form);
final EditText edit_name = (EditText)findViewById(R.id.edit_name);
final EditText edit_lastname = (EditText)findViewById(R.id.edit_lastname);
Bundle bundle = new Bundle();
bundle.putString("name", edit_name.getText().toString());
bundle.putString("lastname", edit_lastname.getText().toString());
Intent form_intent = new Intent(getApplicationContext(), Form.class);
form_intent.putExtras(bundle);
startActivity(form_intent);
}
});
}
}
codice:
public class Form extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
final TextView text_name = (TextView) findViewById(R.id.view_name);
final TextView text_lastname = (TextView) findViewById(R.id.view_lastname);
Bundle bundle = this.getIntent().getExtras();
text_name.setText(bundle.getString("name"));
text_lastname.setText(bundle.getString("lastname"));
}
}
in modo tale da settare il nome inserito, ma dopo la pressione del bottone crasha.