2013-08-16 3 views
1

팝업창에 국가 별 회 전자를 만들고 싶지만 회 전자에 대한 findViewById를 인식하지 못합니다. 이것은 내게 오류를주는 줄입니다 : countryField = (Spinner) dialog.findViewById (R.id.viewSpin);Android 대화창에서 Spinner를 인식하지 못합니다.

protected Dialog onCreateDialog(int id) 
    { 
     switch (id) 
     { 
      case DIALOG_TEXT_ENTRY: 
      // This shows how to add a custom layout to an AlertDialog 
         LayoutInflater factory = LayoutInflater.from(this); 
         final View textEntryView = factory.inflate(R.layout.commentlayout,null); 
         return new AlertDialog.Builder(HomeActivity.this) 
         .setIcon(R.drawable.ic_launcher) 
         .setTitle(R.string.app_name) 
         .setView(textEntryView) 
         .setPositiveButton(R.string.Submit,newDialogInterface.OnClickListener()    
         { 
          public void onClick(DialogInterface dialog, int whichButton) { 

           //System.out.println("You want to submit"); 

        nameField = (EditText) textEntryView.findViewById(R.id.editText1); 
        countryField = (Spinner) dialog.findViewById(R.id.viewSpin);// error line 
        commentField = (EditText) textEntryView.findViewById(R.id.commentField); 

        //get message from message fields 
        String name = nameField.getText().toString(); 
        String count = countryField.getSelectedItem().toString(); 
        String comm = commentField.getText().toString(); 

        //check whether the name field is empty or not 
        if(name.length()>0) { 
      HttpClient httpclient = new DefaultHttpClient(); 
    HttpPost httppost = newHttpPost("URL"); 

    try { 
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); 
    // nameValuePairs.add(new BasicNameValuePair("id", "01")); 
    nameValuePairs.add(new BasicNameValuePair("name", name)); 
    nameValuePairs.add(new BasicNameValuePair("country", count)); 
    nameValuePairs.add(new BasicNameValuePair("comment", comm)); 
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
    httpclient.execute(httppost); 

    nameField.setText(""); //reset the message text field 
    //countryField.setText(""); 
    commentField.setText(""); 
     Toast.makeText(getBaseContext(),"Sent",Toast.LENGTH_SHORT).show(); 
     } catch (ClientProtocolException e) { 
     e.printStackTrace(); 
     } catch (IOException e) { 
     e.printStackTrace(); 
     } 

     ourBrow.reload(); 
     } 
     else { 
     //display message if text field is empty 
     Toast.makeText(getBaseContext(),"All fields are required",Toast.LENGTH_SHORT).show(); 
           } 
          } 
         }) 
       .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() 
       { 
        public void onClick(DialogInterface dialog, int whichButton) 
        {  
        /* User clicked cancel so do some stuff */ 

         System.out.println("You have cancelled"); 
        } 
       }).create(); 
      } 
     return null; 
     } 
+0

무엇을 의미와

countryField = (Spinner)dialog.findViewById(R.id.viewSpin); 

를 교체하려고 뷰에 대한 일부 참조가 아닌 dialogInterface을 필요로? return 'nullpointerexception'입니까? – Gunaseelan

+0

@gunaseelan 그것은 말합니다 : 메서드 findViewById (int)는 DialogInterface 유형에 대해 정의되지 않았습니다 – blessed

+0

왜 다음과 같이'textEntryView'를 사용하지 않습니까? '(Spinner) textEntryView.findViewById (R.id.viewSpin); ' – Gunaseelan

답변

0

이는 이유 때문에 findVIEW라고 불립니다. 그것은

인식하지

countryField = (Spinner) getView().findViewById(R.id.viewSpin); 
+0

getView()를 사용하면 오류가 표시됩니다. – blessed

+0

AN 오류! 나는 당신의 코를 꺼내야 만한다. ... – bofredo

+0

getView() 메소드는 new DialogInterface.OnClickListener() {}에 대해 정의되지 않았다. – blessed

관련 문제