Created
April 10, 2013 04:36
-
-
Save leonguyen/5351822 to your computer and use it in GitHub Desktop.
Android Lab: Dialog with Custom Layout - Create Custom Dialog program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.androidlab; | |
| import android.os.Bundle; | |
| import android.app.Activity; | |
| import android.app.Dialog; | |
| import android.content.Context; | |
| import android.view.Menu; | |
| import android.view.View; | |
| import android.view.View.OnClickListener; | |
| import android.widget.Button; | |
| public class MainActivity extends Activity { | |
| final Context context = this; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| Button button = (Button) findViewById(R.id.buttonCustomDialog); | |
| // Add button listener | |
| button.setOnClickListener(new OnClickListener() { | |
| public void onClick(View arg0) { | |
| // Custom dialog | |
| final Dialog dialog = new Dialog(context); | |
| dialog.setContentView(R.layout.custom_dialog); | |
| dialog.setTitle("Edit"); | |
| Button dialogButton = (Button) dialog.findViewById(R.id.buttonOK); | |
| // if button is clicked, close the custom dialog | |
| dialogButton.setOnClickListener(new OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| dialog.dismiss(); | |
| } | |
| }); | |
| dialog.show(); | |
| } | |
| }); | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) { | |
| // Inflate the menu; this adds items to the action bar if it is present. | |
| getMenuInflater().inflate(R.menu.main, menu); | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment