private int selectedFruitIndex =
0;
private void showMsg2()
{
// Dialog
alertDialog = new AlertDialog.Builder(this).
//
setTitle("确定删除?").
//
setMessage("您确定删除该条信息吗?").
//
setIcon(R.drawable.ic_launcher).
//
setPositiveButton("确定", new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
// TODO Auto-generated method stub
//
}
//
}).
//
setNegativeButton("取消", new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
// TODO Auto-generated method stub
//
}
//
}).
//
setNeutralButton("查看详情", new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
// TODO Auto-generated method stub
//
}
//
}).
//
create();
//
alertDialog.show();
// final String[]
arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };
//
//
Dialog alertDialog = new AlertDialog.Builder(this).
//
setTitle("你喜欢吃哪种水果?").
//
setIcon(R.drawable.ic_launcher)
//
.setItems(arrayFruit, new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
Toast.makeText(PubMainActivity.this, arrayFruit[which],
Toast.LENGTH_SHORT).show();
//
}
//
}).
//
setNegativeButton("取消", new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
// TODO Auto-generated method stub
//
}
//
}).
//
create();
//
alertDialog.show();
//
final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };
//
// Dialog alertDialog = new
AlertDialog.Builder(this).
//
setTitle("你喜欢吃哪种水果?").
//
setIcon(R.drawable.ic_launcher)
//
.setSingleChoiceItems(arrayFruit, 0, new DialogInterface.OnClickListener()
{
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
selectedFruitIndex = which;
//
}
//
}).
//
setPositiveButton("确认", new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
Toast.makeText(PubMainActivity.this, arrayFruit[selectedFruitIndex],
Toast.LENGTH_SHORT).show();
//
}
//
}).
//
setNegativeButton("取消", new DialogInterface.OnClickListener() {
//
//
@Override
//
public void onClick(DialogInterface dialog, int which) {
//
// TODO Auto-generated method stub
//
}
//
}).
//
create();
//
alertDialog.show();
final
String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };
final boolean[]
arrayFruitSelected = new boolean[] {true, true, false, false};
//
// LayoutInflater factory =
LayoutInflater.from(PubMainActivity.this);
//
//获得自定义对话框
// View view =
factory.inflate(R.layout.item_listitem, null);
Dialog alertDialog = new
AlertDialog.Builder(this).
setTitle("你喜欢吃哪种水果?").
setIcon(R.drawable.ic_launcher)
.setMultiChoiceItems(arrayFruit, arrayFruitSelected, new
DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked)
{
arrayFruitSelected[which] = isChecked;
}
}).
setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < arrayFruitSelected.length; i++) {
if (arrayFruitSelected[i] == true)
{
stringBuilder.append(arrayFruit[i] + "、");
}
}
Toast.makeText(PubMainActivity.this, stringBuilder.toString(),
Toast.LENGTH_SHORT).show();
}
}).
setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
create();
alertDialog.show();
}