/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. package com.javalessons.simpledlg1; 

2.  

3. import android.app.Activity

4. import android.app.AlertDialog

5. import android.content.DialogInterface

6. import android.os.Bundle

7. import android.view.View

8. import android.view.View.OnClickListener

9. import android.widget.Button

10. import android.widget.LinearLayout

11.  

12. public class MainActivity extends Activity

13.  

14.   private Button  bt; 

15.   private LinearLayout ll; 

16.   public void onCreate(Bundle savedInstanceState) { 

17.  

18.     super.onCreate(savedInstanceState); 

19.     setContentView(R.layout.activity_main); 

20.      

21.     ll = (LinearLayout) findViewById(R.id.LinearLayout1); 

22.     bt = (Button) findViewById(R.id.button1); 

23.     bt.setOnClickListener(new OnClickListener() { 

24.       @Override 

25.       public void onClick(View v) { 

26.  

27.         AlertDialog.Builder bld = new AlertDialog.Builder(MainActivity.this); 

28.         bld.setTitle("Change colour ?"); 

29.         bld.setMessage("Yes to green"); 

30.         bld.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 

31.           public void onClick(DialogInterface dialog, int id) { 

32.             ll.setBackgroundColor(0xff00ff00); 

33.           } 

34.         }); 

35.         bld.setNegativeButton("No", new DialogInterface.OnClickListener() { 

36.           public void onClick(DialogInterface d, int id) { 

37.             d.cancel(); 

38.           } 

39.         }); 

40.  

41.         AlertDialog dlg = bld.create(); 

42.         dlg.setCanceledOnTouchOutside(true); 

43.         dlg.show(); 

44.       } 

45.     }); 

46.   } 

47.

48.