2017-06-01 6 views
3

AlertDialog Builderにタイトルを追加しようとしています。テーマを追加すると、タイトルが選択領域に移動します。ここ
最初の例である:AlertDialog Builderにテーマを適用すると、タイトルが正常に動作しなくなる

classificationButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(
        new ContextThemeWrapper(mContext, android.R.style.Theme_Holo_Dialog)); 
        //building my selection options 
        builder.setItems(classificationList, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          String desiredClassification = classificationList[which]; 
          if (!getClassification().equals(desiredClassification)) { 
           CallsignContract.updateClassification(desiredClassification, mContext); 
           setClassification(desiredClassification); 
           classificationButton.setText(desiredClassification); 
          } 
         } 
        }); 
        builder.setTitle(R.string.classification_alert_header) 
          .create().show(); 
     } 
    }); 

これは結果です。この第二の試みで
no title
、私はビルダーからalertdialogを作成していることにタイトルを付けます。結果は正しいタイトルですが、タイトルは選択エリアに再び表示されます。

 classificationButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      AlertDialog.Builder builder = new AlertDialog.Builder(
        new ContextThemeWrapper(mContext, android.R.style.Theme_Holo_Dialog)); 
         //building my selection options 
         builder.setItems(classificationList, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          String desiredClassification = classificationList[which]; 
          if (!getClassification().equals(desiredClassification)) { 
           CallsignContract.updateClassification(desiredClassification, mContext); 
           setClassification(desiredClassification); 
           classificationButton.setText(desiredClassification); 
          } 
         } 
        }); 
      AlertDialog alertDialog = builder.create(); 
      alertDialog.setTitle(R.string.classification_alert_header); 
      alertDialog.show(); 
     } 
    }); 


double titles

ありがとうございます!

+0

あなたのタイトルは 'clasificationList'配列内にありませんか? –

+0

@UilqueMessiasいいえclassificationList配列には、Not specified、Unclassified、Confidential、およびSecretのみが含まれます。 – RYDiiN

答えて

1

タイトルを1つだけ表示するには、​​に電話する必要があります。

AlertDialog.Builder builder = new AlertDialog.Builder(
    new ContextThemeWrapper(mContext, android.R.style.Theme_Holo_Dialog) 
); 

//building my selection options 
builder.setItems(classificationList, 
    new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
      String desiredClassification = classificationList[which]; 

      if (!getClassification().equals(desiredClassification)) { 
       CallsignContract.updateClassification(desiredClassification, mContext); 
       setClassification(desiredClassification); 
       classificationButton.setText(desiredClassification); 
      } 
     } 
    } 
); 

AlertDialog alertDialog = builder.create(); 
alertDialog.setTitle(R.string.classification_alert_header); 
// Requesting dialog to remove the title 
alertDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
alertDialog.show(); 
関連する問題