设为首页 加入收藏

TOP

Android中的AlertDialog使用示例二(普通选项对话框)
2016-12-28 08:16:04 】 浏览:5673
Tags:Android AlertDialog 使用 示例 普通 选项 对话


Layout界面代码:



android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:text="普通选项"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="show2"
android:id="@+id/button2" />


Java功能实现代码:


public class AlertDialogDemo extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alertdialog);
}
public void show2(View v){
//实例化建造者
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//设置警告对话框标题
builder.setTitle("选花魁喽");
//定义警告框选择窗体的内容(这里用String数组)
final String[] beautifulGirls = {"芙蓉姐姐","凤姐","范爷","我自己"};
//将数组内的元素设置到dialog的每个item中,并做事件处理(这里用土司)
builder.setItems(beautifulGirls, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(AlertDialogDemo.this,beautifulGirls[which]+"被选中啦",Toast.LENGTH_SHORT).show();
}
});
//显示对话框
builder.show();
}
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java动态代理模式(从现实生活角.. 下一篇Android中的AlertDialog使用示例..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目