4.Activity代码如下:
lain
- package lab.sodino.tanc;
- import android.app.Activity;
- import android.app.Dialog;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class TANCAct extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- btnShow = (Button) findViewById(R.id.btnShow);
- btnShow.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View view) {
- showTANC(
- "This is my custom dialog box",
- "TextContent/nWhen a dialog is requested for the first time, Android calls onCreateDialog(int) from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.",
- }
- });
- }
- private void showTANC(String header, String content, String url) {
- dialog = new Dialog(this, R.style.TANCStyle);
- dialog.setContentView(R.layout.main_dialog);
- dialog.setTitle(header);
- dialog.setCancelable(true);
- textView01 = (TextView) dialog.findViewById(R.id.TextView01);
- textView01.setText(content + content + content);
- btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
- btnCancel.setOnClickListener(new Button.OnClickListener() {
- public void onClick(View view) {
- dialog.cancel();
- }
- });
- dialog.show();
- }
- }