2011-08-11 6 views
2

AlertDialog를 만드는 데 문제가있는 것 같습니다. 내가 뭘 하려는지는 특정 RadioButton이 클릭 될 때 팝업되는 커스텀 AlertDialog를 생성하는 것이다.AlertDialog 생성 관련 문제

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     m_Minutes = -1; 
     m_this=this; 

     String prefName = getString(R.string.prefsfile); 
     SharedPreferences settings = getSharedPreferences(prefName, 0); 
     String defaultTextBackMessage = settings.getString("textBackMessage", getString(R.string.defaultTextBackMessage)); 
     EditText txtMessage = (EditText)findViewById(R.id.editText1); 
     txtMessage.setText(defaultTextBackMessage); 

     final Button button = (Button)findViewById(R.id.button1); 
     final RadioButton manualButton = (RadioButton)findViewById(R.id.radio0); 
     final RadioButton button15 = (RadioButton)findViewById(R.id.radio1); 
     final RadioButton button30 = (RadioButton)findViewById(R.id.radio2); 
     final RadioButton customButton = (RadioButton)findViewById(R.id.radio3); 

     manualButton.setChecked(true); 
     customButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Context c = v.getContext(); 
       LayoutInflater factory = LayoutInflater.from(v.getContext()); 
       final View minuteEntryView = factory.inflate(R.layout.customtime, null); 
       AlertDialog ad = AlertDialog.Builder(c).create(); // this is the trouble line 
      } 
     }); 

나는 AlertDialog ad = AlertDialog.Builder(c).create(); 줄에서 오류가 점점 오전 : 여기 내 관련 코드입니다. 내가 얻는 오류는 The Method Builder(Context) is undefined for the type AlertDialog입니다. 그러나 분명히 Google API Docs에는 Builder 생성자가 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

logcat 오류를 표시 할 수 있습니까? –

+0

@Suri - 런타임 오류가 아닌 컴파일 오류가 발생합니다. – Icemanind

+0

동일한 문제가 발생하여 "새로운"코드를 잊어 버렸습니다. 나는 혼란 한 남자가 필요해! – Ishaan

답변

8

당신이이 말을 should't

AlertDialog ad = new AlertDialog.Builder(c).create(); 

당신이 잊어 버렸습니다 new keyWord .. 분명히 볼 수 있듯이, 그 방법은 발견되지 않았습니다. h는 일반적인 방법으로 생성자를 호출하지만 메서드를 호출하는 방법을 의미합니다.

+0

하하 이것이 내 문제였습니다. 감사합니다 ntc! – Icemanind

0

액티비티에서 onCreateDialog (int id) 메서드를 재정의해야합니다. 이 메서드 내에서 Dialog 객체를 만들고 RadioButton의 onClick 이벤트에서 showDialog (id) 메서드를 사용하여 대화 상자를 호출해야합니다. 아래처럼 당신이 ShowDialog (ID)를 사용하여이 대화 상자를 호출해야합니다

@Override 
protected Dialog onCreateDialog(int id) 
{ 
    // TODO Auto-generated method stub 

    AlertDialog dialog = null; 
    AlertDialog.Builder builder = null; 

    builder = new AlertDialog.Builder(this); 

    switch(id) 
    { 
    case USERNAME_PASSWORD_EMPTY: 

     builder.setMessage("Please Enter Username and Password."); 
     builder.setCancelable(false); 

     builder.setPositiveButton("OK", new DialogInterface.OnClickListener() 
     { 
      public void onClick(DialogInterface dialog, int id) 
      { 
       //Do what you want to do when user clicks OK button of dialog 
      } 
     }); 

     dialog = builder.create(); 

    break; 
    } 

    return dialog; 
} 

방법 :

코드 아래를 참조하십시오 ...

showDialog(USERNAME_PASSWORD_EMPTY);