Cannot get this to work
package com.example.dialog;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity 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.activity_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 on Click(DialogInterface dialog,
int whichButton)
{
Toast.makeText(getBaseContext ()
"cancel clicked!", Toast.LENGTH_SHORT).show();
}
})
.setMultiChoiceItems(items, itemsChecked, new
DialogInterface.onMultiChoiceClickListener() {
@override
public void onClick(DialogInterface dialog, int which,
boolean ischecked) {
Toast.makeText(getBaseContext(),
item[which] =+ (isChecked ? " checked!":)
"unchecked !"),
Toast.LENGTH_SHORT) .SHOW()
}
}
}
)
.Create();
}
return null;
}
}
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
|