//回答问题
protected void dialog2(){
AlertDialog.Builder builder = new AlertDialog.Builder(mQiandaoAct.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("看图答题,答对赢奖励");
// 指定下拉列表的显示数据
final String[] cities = {"广州", "上海", "北京", "香港"};
// 设置一个下拉的列表选择项
builder.setItems(cities, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(mQiandaoAct.this, "选择的城市为:" + cities[which], Toast.LENGTH_SHORT).show();
}
});
builder.show();
}
protected void dialog3(){
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
// AlertDialog.Builder builder = new AlertDialog.Builder(mQiandaoAct.this);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle(problem);
// final String[] sex = {"北京", "上海", "河南","广州"};
final String[] sex = answer.split("\\|");
// 设置一个单项选择下拉框
/**
* 第一个参数指定我们要显示的一组下拉单选框的数据集合
* 第二个参数代表索引,指定默认哪一个单选框被勾选上,
* 第三个参数给每一个单选项绑定一个监听器
*/
builder.setSingleChoiceItems(sex, -1, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Toast.makeText(mQiandaoAct.this, "您的答案是:" + sex[which], Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
// builder.setPositiveButton("确定", new DialogInterface.OnClickListener()
// {
// @Override
// public void onClick(DialogInterface dialog, int which)
// {
//
// }
// });
// builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
// {
// @Override
// public void onClick(DialogInterface dialog, int which)
// {
//
// }
// });
builder.show();
}
转载于:https://www.cnblogs.com/manmanlu/p/3797021.html