2017-03-29 7 views
-3

こんにちは私はダイアログを作成しようとしています[GOT IT! ]と[私がクリックしたとき]私が欲しいAGAIN ME THISを表示しない[完全に閉じ] AGAINボタンダイアログをME THISを示さず、アプリケーションで再度表示されません一度だけダイアログを表示する方法

enter image description here

public boolean Show = false; 

public void IntroSupport(){ 

    Show = true; 

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
    ImageView image = new ImageView(this); 
    image.setImageResource(R.mipmap.ic_launcher); 
    builder.setIcon(R.mipmap.service) 
      .setTitle("Online Support :") 
      .setView(image) 
      .setMessage("Some text") 
      .setNegativeButton("GOT it!",null) 
      .setPositiveButton("Don't Show Me this Again", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 

       } 
      }); 
    builder.setCancelable(false); 
    AlertDialog about = builder.create(); 
    about.show(); 
    TextView messageText = (TextView) about.findViewById(android.R.id.message); 
    messageText.setGravity(Gravity.CENTER); 
    Button nbutton = about.getButton(DialogInterface.BUTTON_NEGATIVE); 
    nbutton.setTextColor(Color.BLACK); 
} 


     @Override 
     public void onPageSelected(int position) { 
      switch (position){ 
       case 0: 
      getSupportActionBar().setTitle(Html.fromHtml("title :"+Pb)); 
        tabLayout.getTabAt(0).setIcon(R.mipmap.ic1vrai); 
        tabLayout.getTabAt(1).setIcon(R.mipmap.ic__2vrai); 
        break; 
       case 1: 

        if(Show == false){ 
         IntroSupport(); 
        } 

        getSupportActionBar().setTitle(Html.fromHtml("("titl"+sus)); 
        tabLayout.getTabAt(1).setIcon(R.mipmap.ic_2faux); 
        tabLayout.getTabAt(0).setIcon(R.mipmap.ic1faux); 
        break; 
      } 
     } 
+0

可能な複製(http://stackoverflow.com/questions/12560931/how-to-show-only-one-dialog- [一度に1つのダイアログを表示する方法?]一度に) –

答えて

1

にあなたを再度開きますユーザーがDon't show me this againボタンを押すと、SharedPreferencesに値を格納できます。次に、SharedPreferencesの値が設定されているかどうかをチェックするif節にダイアログの内容をラップする必要があります。ダイアログを示すかどうかのためにhttps://developer.android.com/reference/android/content/SharedPreferences.html

1

使用SharedPreference:ここ

はSharedPreferencesのドキュメントへのリンクです。このコードを試してみてください:の

public boolean Show = false; 

public void IntroSupport(){ 
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
    ImageView image = new ImageView(this); 
    image.setImageResource(R.mipmap.ic_launcher); 
    builder.setIcon(R.mipmap.service) 
      .setTitle("Online Support :") 
      .setView(image) 
      .setMessage("Somme text") 
      .setNegativeButton("GOT it!",null) 
      .setPositiveButton("Don't Show Me Again", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 
        SharedPreferences.Editor editor = getSharedPreferences("mypref", MODE_PRIVATE).edit(); 
        editor.putBoolean("dontshow", true); 
        editor.commit(); 
       } 
      }); 
    builder.setCancelable(false); 
    AlertDialog about = builder.create(); 
    about.show(); 
    TextView messageText = (TextView) about.findViewById(android.R.id.message); 
    messageText.setGravity(Gravity.CENTER); 
    Button nbutton = about.getButton(DialogInterface.BUTTON_NEGATIVE); 
    nbutton.setTextColor(Color.BLACK); 
} 


    @Override 
    public void onPageSelected(int position) { 
     switch (position){ 
      case 0: 
      getSupportActionBar().setTitle(Html.fromHtml("title :"+Pb)); 
       tabLayout.getTabAt(0).setIcon(R.mipmap.ic1vrai); 
       tabLayout.getTabAt(1).setIcon(R.mipmap.ic__2vrai); 
       break; 
      case 1: 
       SharedPreferences prefs = getSharedPreferences("mypref", MODE_PRIVATE); 
       show = prefs.getBoolean("dontshow", false); 
       if(Show == false){ 
        IntroSupport(); 
       } 

       getSupportActionBar().setTitle(Html.fromHtml("("titl"+sus)); 
       tabLayout.getTabAt(1).setIcon(R.mipmap.ic_2faux); 
       tabLayout.getTabAt(0).setIcon(R.mipmap.ic1faux); 
       break; 
     } 
    } 
+0

私のソリューションは機能しますか? –

関連する問題