2017-01-17 7 views
2

오버플로 메뉴 항목에서 경고 대화 상자를 시작하려고합니다. 대화 상자 레이아웃은 dialog_settings.xml에 있습니다.Android : 오버플로 메뉴 항목에서 경고 대화 상자 시작

import android.support.v7.app.AlertDialog; 

/** Code omitted */ 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     int id = item.getItemId(): 
     if (id == R.id.action_settings) { 
      AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); 
      View mView = getLayoutInflater().inflate(R.layout.dialog_settings, null); 
     } 
     return super.onOptionsItemSelected(item); 
    } 

위의 코드는 오류를 발생시키지 않지만 메뉴 항목을 클릭해도 대화 상자가 표시되지 않습니다. 내 앱과 Android Studio에 Android 4.1.2, API 16을 사용하고 있습니다.

나는이 question from 2012보다 간단한 해결책을 찾기를 바랍니다.

답변

1

대화 상자를 만들고 있지만 만들고 표시하지는 않습니다. 어쩌면 다음과 같은 것을 원할 것입니다 :

if(id == R.id.action_settings) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setView(R.layout.dialog_settings) //set the view 
     .create() //create the dialog 
     .show(); //show the dialog 

    return true; 
}