设为首页 加入收藏

TOP

Android中的AlertDialog使用示例三(单向选择确定对话框)
2016-12-28 08:16:04 】 浏览:7081
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="show3"
android:id="@+id/button3" />


Java功能实现代码:


public class AlertDialogDemo extends AppCompatActivity {
int index=0;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alertdialog);
}
public void show3(View v){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("挑媳妇儿");
final String[] beautifulGirls = {"芙蓉姐姐","凤姐","范爷","我自己"};
builder.setSingleChoiceItems(beautifulGirls, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
index = which;
}
});
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(AlertDialogDemo.this,beautifulGirls[index]+"是你的媳妇了",Toast.LENGTH_SHORT).show();
}
});
builder.show();
}
}


优化空间很大,大家都可以玩玩。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android中的AlertDialog使用示例.. 下一篇Java集合框架之Collection接口

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目