代码:
// 带列表的列表对话框
Button button2=(Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] items=new String[]{"Java","C#","C++","Android","zigbee"};// TODO Auto-generated method stub
Builder builder=new AlertDialog.Builder(MainActivity.this);
builder.setIcon(R.drawable.icon_sina);
builder.setTitle("请选择你喜欢 的语言");
// 添加列表项
builder.setItems(items, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "你选择了"+items[which]+"语言", Toast.LENGTH_LONG).show();
}
});
builder.create().show();
}
});