我正在使用http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/教程来显示丝绸菜单并且工作得很好.
现在我想知道一个特定的ListvIEw项目,我需要显示带有是或否按钮的对话框.所以我是新手.任何人都可以帮我解决这个问题吗?
这就是我的滑块菜单的样子,你可以看到如果我点击第三项我需要显示如图所示的对话框
解决方法:
如果您正在学习本教程,那么请将MainActivity中的displayVIEw(int position)方法更改为:
private voID displayVIEw(int position) { // update the main content by replacing fragments Fragment fragment = null; switch (position) { case 0: fragment = new HomeFragment(); break; case 1: fragment = new FindPeopleFragment(); break; case 2: AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( MainActivity.this); // set Title alertDialogBuilder.setTitle("Alert"); // set dialog message alertDialogBuilder .setMessage("Pelase select your choice") .setCancelable(false) .setPositivebutton("Yes",new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int ID) { //do whatever you want to do when user clicks ok } }) .setNegativebutton("No",new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog,int ID) { // if this button is clicked, just close // the dialog Box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); break; case 3: fragment = new CommunityFragment(); break; case 4: fragment = new PagesFragment(); break; case 5: fragment = new WhatsHotFragment(); break; default: break; } if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction() .replace(R.ID.frame_container, fragment).commit(); // update selected item and Title, then close the drawer mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); setTitle(navMenuTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } else { // error in creating fragment Log.e("MainActivity", "Error in creating fragment"); }}
总结 以上是内存溢出为你收集整理的在片段android中显示对话框全部内容,希望文章能够帮你解决在片段android中显示对话框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)