常用控件的使用
来源:互联网 发布:免费发短信软件 编辑:程序博客网 时间:2024/06/10 11:19
单选框
<RadioGroup android:id="@+id/radio_g" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <RadioButton android:id="@+id/radioMale" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:checked="true" android:text="男" android:textSize="20sp" /> <RadioButton android:id="@+id/radilFemale" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="女" android:textSize="20sp" /> </RadioGroup> </LinearLayout>
单选框的监听
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {switch (checkedId) {case R.id.radioMale:sex = "男";break;case R.id.radilFemale:sex = "女";break;default:break;}}});
复选框
<LinearLayout Android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <CheckBox android:id="@+id/box1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="玩游戏" android:textSize="18sp" /> <CheckBox android:id="@+id/box2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="听音乐" android:textSize="18sp" /> <CheckBox android:id="@+id/box3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="看电影" android:textSize="18sp" /> <CheckBox android:id="@+id/box4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="敲代码" android:textSize="18sp" /> </LinearLayout>
复选框的监听
public void selectChange() {box1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {if (isChecked)box1Str = (String) buttonView.getText();else {box1Str = "";}}});box2......}
对话框 选择性别(单选)
btn_sex.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {AlertDialog.Builder dialog = new AlertDialog.Builder(FinshActivity.this);dialog.setTitle("请选择");dialog.setSingleChoiceItems(sexs, flag,new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {flag = which;}});dialog.setPositiveButton("确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {btn_sex.setText(sexs[flag]);}});dialog.setNegativeButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {// TODO}});dialog.show();}});
对话框 多选
// 个人爱好的监听事件btn_hobby.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {AlertDialog.Builder dialog = new AlertDialog.Builder(FinshActivity.this);dialog.setTitle("请选择");dialog.setMultiChoiceItems(hobbys, check,new DialogInterface.OnMultiChoiceClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which, boolean isChecked) {check[which] = isChecked;}});dialog.setPositiveButton("确定",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {selectString ="";for (int i = 0; i < hobbys.length; i++) {if (check[i] == true) {selectString = selectString + " "+ hobbys[i];btn_hobby.setText(selectString);}}}});dialog.setNegativeButton("取消",new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {// TODO}});dialog.show();}});
对话框 修改密码(弹出一个新的视图) (附文件保存)
btn_changepwd.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {AlertDialog.Builder dialog = new AlertDialog.Builder(FinshActivity.this);View view = getLayoutInflater().inflate(R.layout.pwd_layout,null);newpwd = (EditText) view.findViewById(R.id.newpwd);oknewpwd = (EditText) view.findViewById(R.id.oknewpwd);dialog.setView(view);dialog.setPositiveButton("确定", newDialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {String cpwd=newpwd.getText().toString();String cokpwd=oknewpwd.getText().toString();if (cpwd.equals(cokpwd)) {try {File file=new File(FinshActivity.this.getFilesDir(),"info.txt");FileOutputStream fosStream =new FileOutputStream(file);String info = qq+"##"+cpwd;fosStream.write(info.getBytes());fosStream.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}Toast.makeText(FinshActivity.this,"修改密码成功!", Toast.LENGTH_SHORT).show();}else {Toast.makeText(FinshActivity.this,"修改密码失败!", Toast.LENGTH_SHORT).show();}}});dialog.setNegativeButton("取消", newDialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {//TODO}});dialog.show();}});新建一个R.layout.pwd_layout文件读取:try {File file = new File(this.getFilesDir(), "info.txt");FileInputStream fis = new FileInputStream(file);BufferedReader br = new BufferedReader(new InputStreamReader(fis));String info = br.readLine();qq = info.split("##")[0];pas = info.split("##")[1];} catch (FileNotFoundException e1) {// TODO Auto-generated catch blocke1.printStackTrace();} catch (IOException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}
0 0
- 常用控件的使用
- 常用控件的使用
- EXTJS 常用控件的使用
- EXTJS 常用控件的使用
- MFC常用控件的使用
- android常用的控件ViewPager的使用
- zt:常用日历控件的使用
- Android常用控件之ExpandableList的使用
- Android常用控件之SeekBar的使用
- Android常用控件之RatingBar的使用
- Android常用控件之FragmentTabHost的使用
- android 常用控件的使用 TextView EditTextView
- Android常用控件之GridView的使用
- Android常用控件之ViewPager的使用
- Android常用控件之SeekBar的使用
- talend的常用控件使用教程
- VC中常用控件的使用
- extjs 常用控件的使用 table layout
- 工具类小技巧集合
- NYOJ325 zb的生日(01背包,深搜DFS)
- 左旋字符串
- weblogic10部署润乾报表中文乱码问题的解决
- HTTP通信--Android客户端与Servlet通信
- 常用控件的使用
- Hibernate
- 解决loading descriptor for xxx 慢的问题
- Linux下安装go1.7.3
- spark性能优化:数据倾斜调优
- 树莓派sip视频电话-1:exosip2ctype+python使用硬件编解码
- 类加载-反射(JAVA灵魂)
- 如何使用httpclient进行NTLM认证登录
- Linux : E: Unable to locate package XXX