public class MainActivity extends Activity {
CharSequence[] items={"google","apple","Microsoft"};
boolean[] itemschecked=new boolean[items.length];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
如何替换showDialog
public void OnClick(View v)
{
showDialog(0);
}
@Override
rotected Dialog onCreateDialog(int id)
{switch(id)
{ case 0:
Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("This is dialog with some simple text...");
builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(getBaseContext(), "ok clicked!",Toast.LENGTH_SHORT).show();
}
}
);
builder.setNegativeButton("cancel",new DialogInterface.OnClickListener()
{public void onClick(DialogInterface dialog,int whichButton)
{Toast.makeText(getBaseContext(), "cancel clicked!", Toast.LENGTH_SHORT).show();
}
}
);
builder.setMultiChoiceItems(items, itemschecked, new DialogInterface.OnMultiChoiceClickListener()
{public void onClick(DialogInterface dialog,int which,boolean ischecked)
{ Toast.makeText(getBaseContext(), items[which]+(ischecked ? "checked!" :" unchecked!"),Toast.LENGTH_SHORT).show();
}
}
);
return builder.create();
}
return null;
}
}