Android newbie learning dialogs = CRASH

I'm trying to learn custom dialogs. I made one with a button in it and it comes up fine and I can hit breakpoints in the constructor and onCreate method, but when I click the button it crashes without ever getting to the button handler.

The dialog layout XML (my_dialog_layout.xml) is:

<?xml version="1.0" encoding="utf-8"?>
     android:text="Click Me"
  <TextView android:id="@+id/text"
    android:text="Click this button: " 

... and the Dialog's java file is:

import android.os.Bundle;
import android.widget.Toast;
import android.view.View;
import android.content.Context; 

public class MyDialog extends Dialog {

    public MyDialog(Context context) {

    public void AButtonHandler(View target) {
        int i = 0;   // just a placeholder to set a breakpoint at
        i++;         //   "                 "
//       Toast.makeText(this, "in AButtonHandler", Toast.LENGTH_LONG).show();

    public void onCreate(Bundle savedInstanceState) {
  //      Toast.makeText(this, "Dialog onCreate", Toast.LENGTH_LONG).show();

When I click AButton it crashes in the debugger before getting to my breakpoint in AButtonHandler with " Thread [<1> main] (Suspended (exception IllegalStateException)) View$1.onClick(View) line: 2059 Button(View).performClick() line: 2408 ..."

Also notice the commented-out Toast's. I wanted to put Toasts in but thye compiler gives me: The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (MyDialog, String, int) What am I doing wrong?

Thanks in advance!


Second problem: A Dialog is not a Context. It has a Context. Use Toast.makeText(getContext(), ...).

First problem: Same thing. The method needs to be in the activity, not the dialog. (I should mention that I never tried onClick in a dialog. You may need to use a traditional OnClickListener.)

Side note: Function names should start with lower case.

Need Your Help

MonoTouch. Removing a particular UIImage SubView from ViewController

ios uiimageview monotouch subview

How to find and remove a UIImageView from the collection of ParentViewController.View.Subviews very quick?

how to create an automatic logout script in php

php mysql

im trying to create an auto logout system that will automatically log out of the system when the page is inactive,i am a newbie and when i added code to my login page im getting these warnings

Submit data to Google Spreadsheet Form from Objective-C

objective-c ios google-spreadsheet

Is there a library, blog post, etc. that can be used to submit data to a Google Spreadsheet using Forms ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.