- package com.test;
-
-
//import java.net.URISyntaxException;
-
-
import android.app.Activity;
-
import android.os.Bundle;
-
import android.os.Environment;
-
import android.util.Log;
-
import android.view.View;
-
import android.widget.Button;
-
import android.widget.Toast;
-
-
public class TestActivity1 extends Activity {
-
/** Called when the activity is first created. */
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.main);
-
-
Button btn = (Button) this.findViewById(R.id.button1);
-
btn.setOnClickListener(new View.OnClickListener() {
-
public void onClick(View v) {
-
-
// Show a hint message box and auto disappear after timeout
-
Toast.makeText(getApplicationContext(), "Hello Android, I am coming....",
-
Toast.LENGTH_LONG).show();
-
}
-
});
-
}
-
}
-----------------------------------------------------------------------------
搞个有按钮的对话框,点击button退出activity.
- Dialog dlg = new AlertDialog.Builder(TestActivity1 .this)
-
.setMessage(R.string.hello)
-
.setCancelable(false) // disable cancel action, hardware back button
-
.setPositiveButton(R.string.OK,
-
new DialogInterface.OnClickListener() {
-
-
public void onClick(DialogInterface dialog, int which) {
- TestActivity1.this.finish();
-
}
-
-
}).create();
-
-
-
dlg.show();