app选择不再提醒,对话框将不再提示
2015-09-14 20:16
204 查看
app 在首次登陆的时候,有提示需求弹出对话框。如果点击不再提示,下次登录的时候。对话框将 不再弹出。
public class MainActivity extends ActionBarActivity { private AlertDialog di; private View checkbox; private CheckBox cBox; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //加载checkbox.xml 文件 LayoutInflater lauoutInflater=LayoutInflater.from(this); checkbox = lauoutInflater.inflate(R.layout.checkbox, null); //获取.xml文件的按钮 cBox=(CheckBox)checkbox.findViewById(R.id.check); //通过sharedPreferences来保存信息 SharedPreferences pre=getSharedPreferences("checkvalue", MODE_PRIVATE); String value=pre.getString("ischeck", ""); //判断接受到的信息 if (value.endsWith("1")) { //如果选择的是1,则对话框就不再弹出 createDialog().dismiss(); }else { //如果没有选择,则对话框继续弹出 createDialog().show(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } private AlertDialog createDialog(){ di=new AlertDialog.Builder(this).setTitle("友情提示ʾ").setMessage("为了保证随时接收到呼叫,需要root权限。如有需要请到设置中进行修改。").setView(checkbox) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which) { //将数据保存到sharedPerferences中: SharedPreferences pre=getSharedPreferences("checkvalue", MODE_PRIVATE); Editor editor=pre.edit(); //判断cBox是否被选中 if (cBox.isChecked()) { editor.putString("ischeck", "1"); }else { editor.putString("ischeck", "0"); } //提交选择的check,并且保存在pre中 editor.commit(); } }).create(); return di; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 添加checkbox.xml文件 `` <?xml version="1.0" encoding="utf-8"?> <CheckBox xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/check" android:text="不再提醒" > </CheckBox>
相关文章推荐
- Mapped Statements collection does not contain value for
- Unity物理引擎:Charactor Controller简介
- IOS 学习---通过block自定义button的点击事件
- Android之实用库xUtils四大模块以及用ViewInject代替findViewById()
- 关于向android studio导入项目,gradle报错的问题
- Android(java)学习笔记249:ContentProvider使用之获得系统联系人信息01
- Android基础入门教程——7.5.4 WebView文件下载
- [置顶] android studio 查看源码时有些类显示 can not resolve 的问题
- Objective-C 【NSDictionary 文件操作(重点)&简写形式】
- iOS计算缓存大小、清除缓存
- Android Pay正式启用 支付宝们还好吗
- 论题Cascade Object Detection with Deformable Part Models一个怀疑
- Android特效 五种Toast详解
- OC-字符串集合补充
- Unity AssetBundle资源打包,Depend依赖关系
- Android Studio(八):Android Studio设置教程
- Android Studio(八):Android Studio设置教程
- 我是如何自学Android,资料分享(2015 版)
- Unity物理引擎:Colliders简介
- Android输入法back出现黑块