为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

Dialog提示用户打开网络连接后返回Activity的有关问题

2018-04-29 3页 doc 15KB 9阅读

用户头像

is_337177

暂无简介

举报
Dialog提示用户打开网络连接后返回Activity的有关问题Dialog提示用户打开网络连接后返回Activity的有关问题 Dialog提示用户打开网络连接后返回Activity的问题 一个android应用,先保存用户的手机号、确认网络连接打开、GPS打开,然后跟远程服务器建立连接,自己GPS定位。 保存用户的手机号、提示打开网络连接、提示打开GPS,用了3个Dialog。在Activity的onCreate()方法里面先判断前面3个条件是否满足,不满足就显示Dialog,为了不让3个Dialog挤在一起,用了下面的代码: public void onCreate(Bund...
Dialog提示用户打开网络连接后返回Activity的有关问题
Dialog提示用户打开网络连接后返回Activity的有关问题 Dialog提示用户打开网络连接后返回Activity的问题 一个android应用,先保存用户的手机号、确认网络连接打开、GPS打开,然后跟远程服务器建立连接,自己GPS定位。 保存用户的手机号、提示打开网络连接、提示打开GPS,用了3个Dialog。在Activity的onCreate()方法里面先判断前面3个条件是否满足,不满足就显示Dialog,为了不让3个Dialog挤在一起,用了下面的代码: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); if((myPhoneNumber = getMyPhoneNumber()) == null){ showDialog(DIALOG_MY_PHONE_NUMBER); } else if (!isNetworkConnected()){ showDialog(DIALOG_NETWORK); } else if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { showDialog(DIALOG_GPS); } else { …… //跟远程服务器建立连接 //GPS定位 …… } } Dialog定义在 @Override protected Dialog onCreateDialog(int id){ Dialog dialog = null; switch(id){ case DIALOG_MY_PHONE_NUMBER: LayoutInflater factory = LayoutInflater.from(MainActivity.this); final View dialogView = factory.inflate(R.layout.phone_number_dialog, (ViewGroup)findViewById(R.id.layout_root)); dialog = new AlertDialog.Builder(MainActivity.this) .setTitle( 手机号码设置 ) .setView(dialogView) .setPositiveButton( 设置 , new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { EditText text = (EditText)dialogView.findViewById(R.id.my_phone_number); SharedPreferences settings = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString( myPhoneNumber , text.getText().toString()); editor.commit(); Intent intent = new Intent(); intent.setClass(MainActivity.this, MainActivity.class); MainActivity.this.startActivity(intent); } }).setNegativeButton( 取消 , new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { MainActivity.this.finish(); } }) .create(); break; case DIALOG_NETWORK: dialog = new AlertDialog.Builder(MainActivity.this) .setTitle( 网络设置提示 ) .setMessage( 网络连接不可用,是否进行设置? ) .setPositiveButton( 设置 , new DialogInterface.OnClickListener() {
/
本文档为【Dialog提示用户打开网络连接后返回Activity的有关问题】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索