displaying a dialog using an activity?

Posted by ricardo123 on Stack Overflow See other posts from Stack Overflow or by ricardo123
Published on 2011-06-26T23:47:35Z Indexed on 2011/06/27 0:22 UTC
Read the original article Hit count: 122

Filed under:
|
|
|

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:

    }}}

© Stack Overflow or respective owner

Related posts about java

Related posts about android