Android开发对话框之单选对话框的…
来源:互联网 发布:dll反编译成c语言 编辑:程序博客网 时间:2024/06/09 23:03
在values文件夹下建立
compnay.xml
<?xmlversion="1.0" encoding="utf-8"?>
<resources>
</resources>
ceo.xml
<?xmlversion="1.0" encoding="utf-8"?>
<resources>
</resources>
file.xml
<?xmlversion="1.0" encoding="utf-8"?>
<resources>
</resources>
我们main.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
我们.java文件
packagecom.example.radiodialogdemo;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.app.AlertDialog;
importandroid.app.Dialog;
importandroid.content.DialogInterface;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.TextView;
public class MainActivityextends Activity {
private Buttonbutton=null;
private TextViewmysel=null;
private TextView company=null;
private TextViewceo=null;
private TextViewfile=null;
private intchNum=0;
@Override
protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.button=(Button)super.findViewById(R.id.sel);
this.mysel=(TextView)super.findViewById(R.id.mysel);
this.company=(TextView)super.findViewById(R.id.company);
this.ceo=(TextView)super.findViewById(R.id.ceo);
this.file=(TextView)super.findViewById(R.id.file);
//为我们的按钮添加点击事件
this.button.setOnClickListener(newOnClickListenerImp());
}
public class OnClickListenerImpimplements OnClickListener{
public void onClick(View arg0){
//创建我们的单选对话框
Dialog dialog=newAlertDialog.Builder(MainActivity.this)
.setTitle("选择公司")
.setIcon(R.drawable.ic_launcher)
.setPositiveButton("确定", newDialogInterface.OnClickListener() {
public voidonClick(DialogInterface dialog, int which) {
MainActivity.this.mysel.setText("您的选择是"+MainActivity.this.getResources().getStringArray(R.array.company)[chNum]);
}
})
.setNegativeButton("取消", newDialogInterface.OnClickListener() {
public voidonClick(DialogInterface dialog, int which) {
}
})
.setSingleChoiceItems(R.array.company, 0, newDialogInterface.OnClickListener() {
//上边第一个表示的是公司数组列表,第二个参数表示默认选择的,第三个监听器
public voidonClick(DialogInterface dialog, int which) {
chNum=which;
MainActivity.this.company.setText("公司:"+MainActivity.this.getResources().getStringArray(R.array.company)[which]);
MainActivity.this.ceo.setText("ceo:"+MainActivity.this.getResources().getStringArray(R.array.ceo)[which]);
MainActivity.this.file.setText("行业:"+MainActivity.this.getResources().getStringArray(R.array.file)[which]);
}
})
.create();
dialog.show();
}
}
}
0 0
- Android开发对话框之单选对话框的…
- Android简单对话框、输入对话框、单选对话框、复选对话框、列表对话框、自定义对话框、时间对话框
- Android开发对话框之多选对话框的…
- Android开发基础之AlertDialog的单选对话框的使用
- android 单选对话框
- Android之单选按钮对话框
- Android之单选按钮对话框
- Android通知之单选对话框通知
- Android的普通对话框,单选和多选对话框
- Android开发之对话框
- android,单选对话框,进度条对话框
- Android单选对话框的创建
- android通知对话框、多选对话框、单选对话框
- Android-Dialog对话框 全解(普通对话框,单选对话框,多选对话框,列表对话框,自定义对话框,Activity对话框)
- Android开发之列表对话框的使用
- Android 实现单选对话框
- AlertDialog创建6种对话框的用法 (对话框,单选对话框,多选对话框,列表对话框,自定义对话框,退出对话框)
- Android对话框之对话框风格的窗体
- 如何结束我们的android程序
- VC编程练习之API笔记(四)
- 恶意移动代码------浏览器脚本
- Android开发之对话框事件之点击手…
- Android开发之列表对话框的使用
- Android开发对话框之单选对话框的…
- Android开发对话框之多选对话框的…
- Android输入密码密文显示
- android中LayoutInflater的使用
- 安卓中颜色种类
- 日期选择对话框
- 时间选择对话框
- java当中实现线程的两种方法
- java线程实现的两种方式实例