2011-04-22 8 views
2

안드로이드는 나는 그것의 텍스트 값을 설정하는 텍스트 뷰를 전망하지만 AlertDialog를 구축하고 액세스 할 수 트링하고있다.문제 가져 오는 중 오류 구성 요소 -

private void ShowLogDialog() { 
    AlertDialog ad = new AlertDialog.Builder(this).create(); 
    ad.setIcon(R.drawable.icon); 
    ad.setTitle("Ultimate Logs"); 
    ad.setView(LayoutInflater.from(this).inflate(R.layout.log_layout, null)); 
    TextView text = (TextView)ad.findViewById(R.id.logTextView_log); // RETURNS NULL 
    //Log.i(TAG, "Into ShowLogDialog : GoT TextView = " + text); 
    //String logsText = ""; 
    //text.setText(logsText); 
    ad.setButton("Ok", new DialogInterface.OnClickListener() {   
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      dialog.dismiss(); 
     } 
    }); 
    ad.show(); 
} 

log_layout.xml

<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" 
      android:orientation="vertical" android:scrollbars="vertical" android:scrollbarAlwaysDrawVerticalTrack="true" xmlns:android="http://schemas.android.com/apk/res/android"> 
      <TextView android:layout_height="wrap_content" android:text="TextView" android:id="@+id/**logTextView_log**" android:layout_width="wrap_content"></TextView> 
     </LinearLayout> 

왜 내가 텍스트 뷰에 액세스 할 수 없습니다 : 여기에 코드입니까? null를 돌려 주어, NullPointerException를 Throw합니다. findBiewById를 사용하여 직접 액세스 할 수 없으므로 ad.findViewById를 사용하고 있지만 null 만 수신합니다. 아무도 내가 잘못 가고 있다는 것을 알 수 있도록 도와 줄 수 있습니까?

감사합니다.

+0

AlertDialog의 텍스트 글꼴 크기를 설정할 수있는 방법이 있습니까? 내 말은, SetMessage()에 추가 된 텍스트의 크기를 변경할 수 있습니까? 이것이 성취 될 수 있다면, 또한 나의 일을 할 수 있습니다. – Tvd

답변

2

이것은 작동하는 것 같습니다. 재미있어!

 AlertDialog.Builder builder= new AlertDialog.Builder(this); 
     LayoutInflater inflater= getLayoutInflater(); 
     final View myView= inflater.inflate(R.layout.alert_dialog_text_entry, null); 
     builder.setTitle("About"); 
     builder.setMessage("Test"); 
     builder.setView(myView); 
     AlertDialog alert= builder.create(); 
     TextView stateful= (TextView)myView.findViewById(R.id.TextView01); 
     stateful.setText("More Testing"); 
     Log.d(Utilities.TAG,stateful.toString()); 
     alert.show(); 
+0

감사합니다. myView.findViewbyId()가 작업을 수행했습니다. – Tvd

0

무엇을 의미합니까?

android:id="@+id/**logTextView_log**

** 의미 ..?

+0

그냥 제거 ** n 확인 –

+0

여기에 게시 할 때 ID 텍스트를 굵게 표시했습니다. 그게 전부 야. 다른 건 없어. – Tvd

+0

이 줄을 주석 처리하십시오. TextView text = (TextView) ad.findViewById (R.id.logTextView_log); n 확인 대화 상자 n textview가 표시되거나 표시되지 않습니다. –

0

왜 먼저 View 변수에 LayoutInflater.from(this).inflate(R.layout.log_layout, null)을 반환하지? (아래 코드는 테스트되지 않았습니다.)

ad.setTitle("Ultimate Logs"); 
    View inflatedView = LayoutInflater.from(this).inflate(R.layout.log_layout, null);   
    TextView text = (TextView)inflatedView.findViewById(R.id.logTextView_log); // RETURNS NULL 
    Log.i(TAG, "Into ShowLogDialog : GoT TextView = " + text); 
    String logsText = ""; 
    text.setText(logsText); 
    ad.setView(inflatedView); 
    ad.setButton("Ok", new DialogInterface.OnClickListener() { 
+0

그런 다음 ad.show()에서 "requestFeature()를 호출하기 전에 호출해야 함"예외가 발생합니다. – Tvd