2011-09-04 4 views
2

Android의 PopupWindow에있는 TextView의 텍스트를 동적으로 변경하는 데 문제가 있습니다. LayoutInflaterViewGroup을 사용하여 PopupWindow 내부의 TextView 요소를 참조했지만 텍스트가 업데이트되지 않습니다. 어떤 도움이라도 대단히 감사하게 될 것입니다! :)PopupWindow의 TextView 텍스트가 작동하지 않습니다.

내 코드는 다음과 같다 :

private void popupWindow() { 
     try { 
      LayoutInflater inflater = (LayoutInflater) SwingSpeed.this 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View layout = inflater.inflate(R.layout.popup_recording, 
        (ViewGroup) findViewById(R.id.popup_element)); 
      pw = new PopupWindow(inflater.inflate(R.layout.popup_recording, 
        null, false), 480, 800, true); 
      pw.showAtLocation(findViewById(R.id.swingspeed), Gravity.CENTER, 0, 
        0); 
      recording_text = (TextView) layout 
        .findViewById(R.id.recording_text); 
      recording_text.setText("Recording"); //Update the TextView 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

답변

5

문제는 다음과 같습니다

recording_text = (TextView) pw.getContentView(). 
       findViewById(R.id.recording_text); 
이렇게

recording_text = (TextView) layout.findViewById(R.id.recording_text); 

: 당신은 레이아웃을 대신에 두 번, 팽창하는

및이 줄이 전혀 필요하지 않습니다.

View layout = inflater.inflate(R.layout.popup_recording, 
       (ViewGroup) findViewById(R.id.popup_element)); 
+0

우수합니다. 정말 고맙습니다!! – BGM

관련 문제