FIRST CLASS:
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
String s;
TextView t;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = (TextView) findViewById(R.id.TextView01);
Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(HelloWorld.this,
SecondActivity.class);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String s = data.getStringExtra("name");
t.setText(s);
}
}
SECOND CLASS:
public class SecondActivity extends Activity {
EditText te;
String s;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
//TextView te=(TextView)findViewById(R.id.TextView01);
te=(EditText)findViewById(R.id.EditText01);
Button b=(Button)findViewById(R.id.Button01);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
s=te.getText().toString();
Intent intent = new Intent();
intent.putExtra("name", s);
setResult(RESULT_OK, intent);
finish();
}
});
}
}
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
String s;
TextView t;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t = (TextView) findViewById(R.id.TextView01);
Button button = (Button) findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(HelloWorld.this,
SecondActivity.class);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String s = data.getStringExtra("name");
t.setText(s);
}
}
SECOND CLASS:
public class SecondActivity extends Activity {
EditText te;
String s;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
//TextView te=(TextView)findViewById(R.id.TextView01);
te=(EditText)findViewById(R.id.EditText01);
Button b=(Button)findViewById(R.id.Button01);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
s=te.getText().toString();
Intent intent = new Intent();
intent.putExtra("name", s);
setResult(RESULT_OK, intent);
finish();
}
});
}
}
No comments:
Post a Comment