displaying a dialog using an activity?

what am i doing wrong here or what do i need to add?

package dialog.com;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class Dialog extends Activity {
    CharSequence [] items = { "google", "apple", "microsoft" };
    boolean [] itemschecked = new boolean [items.length];
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn = (Button) findViewById(R.id.btn_dialog);
        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(0);
            }
        });
    }
    @Override
    protected Dialog onCreateDialog(int id) {
        switch(id) {
        case 0:
            return new AlertDialog.Builder(this)
            .setIcon(R.drawable.icon)
            .setTitle("This is a Dialog with some simple text...")
            .setPositiveButton("ok", new
                    DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,
                        int whichbutton)
                {
                    Toast.makeText(getBaseContext(),
                            "OK Clicked!", Toast.LENGTH_SHORT).show();
            }
        });
            .setNegativeButton("cancel",new
                    DialogInterface.OnclickListener() {
                public void onClick(DialogInterface dialog,
                        int whichButton)
                {Toast.makeText(getBaseContext(),
                        "cancel clicked!", Toast.LENGTH_SHORT).show();
                }
            });
            .setMultiChoiceItems(itemschecked, new
                    DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(dialoginterface dialog, int which, boolean isChecked) {
                    Toast.makeText(getBaseContext(),
                            items[which] + (isChecked ? " checked!":
                                "unchecked!"),
                                Toast.LENGTH_SHORT).show();
                }
            }
            )
            .create();
        }
        return null:

    }}}

Answers


Rename your class to something other than Dialog. Call it CustomDialog or something.


This is example from "Begining Android Application Development" book.

It didn't worked so i added this:

  1. import your.package.name.R;
  2. And delete the last @override, the one for onClick() method. (Just delete annotation, not the method.)
  3. I deleted the line: .setIcon(R.drawable.icon), couldn't fix that.

After this code worked.


Need Your Help

Cannot deploy MVC 4 to server

c# asp.net asp.net-mvc web-deployment

My web application is just a simple web application made in VS 2010 MVC 4 without any code from outside. It's just default application of VS 2010. I have Deluxe Windows Hosting with Plesk. I've never

Inserting an indexed element of array into textbox while in 'edit' mode

html arrays angularjs input

I am making a simple To Do list using AngularJS v1.4.3. Here is a plunkr of my work so far.