public class main extends Activity {
private Button AlertButton;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertButton = (Button) findViewById(R.id.AlertButton);
AlertButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
new AlertDialog.Builder(main.this).setTitle("AlertTest")
.setMessage("Alert Body").setPositiveButton("Exit"
,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
//要做的事情.....
}
}).show();
}
});
}
2010年4月29日 星期四
不同的Activity之間資料的傳遞
//發送端
import andoird.os.Bundle;
....
..
.
public class sendData extends Activity{
public onCreate(Bundle states) {
super.onCreate(states);
setContentView(R.layout.main);
......
....
..
Intent intent = new Intent();
intent.setClass(sendData.this, receiveData.class);
Bundle bundle = new Bundle();
bundle.putString("Jason","Jason");
bundle.putDouble("double",9.99d);
intent.putExtras(bundle);
startActivity(intent);
}
}
//接收端
import andoird.os.Bundle;
....
..
.
public class sendData extends Activity{
public onCreate(Bundle states) {
super.onCreate(states);
setContentView(R.layout.main);
......
....
..
Intent intent = new Intent();
intent.setClass(sendData.this, receiveData.class);
Bundle bundle = new Bundle();
bundle.putString("Jason","Jason");
bundle.putDouble("double",9.99d);
intent.putExtras(bundle);
startActivity(intent);
}
}
//接收端
import andoird.os.Bundle;
...
..
.
public class receiveData extends Activity{
public onCreate(Bundle states) {
super.onCreate(states);
setContentView(R.layout.main);
......
....
..
Bundle bundle = this.getIntent().getExtras();
String MyName = bundle.getString("Jason");
double width = bundle.getDouble("double");
}
}
訂閱:
文章 (Atom)