2017-11-28 1 views
1

예, 이전에 비슷한 질문을했지만 그 중 많은 부분을 시도했습니다. 그래서 TextView에서 텍스트를 부풀려진 레이아웃으로 설정하는 데 문제가 있습니다. setContentView() 시도한 다음 작동하지만 메뉴가있는 activity_main.xml 작동하지 않습니다. 그래서 필자는 필요한 TextView로 레이아웃을 팽창 시키려고 노력했다. setText() 할 때 단지 그것을 표시하지 않습니다.팽창 된 레이아웃의 setText()를 TextView()에 사용한 후 텍스트가 표시되지 않습니다.

public void bodAlg() { 
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View vi = inflater.inflate(R.layout.layout1, null); 

    EditText editText = (EditText) vi.findViewById(R.id.bod_servers); 
    String[] serversArray = editText.getText().toString().split(", "); 

    TextView textView = (TextView) vi.findViewById(R.id.bod_serv_array); 
    textView.setText(Arrays.toString(serversArray)); 
} 

그리고 여기에 XML입니다 : 여기 내 코드는

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<RelativeLayout 
    android:id="@+id/rl_01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:id="@+id/ll_01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <EditText 
      android:id="@+id/bod_servers" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Cray CS-Storm, Vulcan – Blue Gene/Q, Blue Gene/Q, Stampede – PowerEdge C8220, Piz Daint – Cray XC30" 
      android:textColor="@color/common_google_signin_btn_text_dark_focused" 
      android:textSize="13sp"/> 

     <TextView 
      android:id="@+id/bod_serv_array" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:textSize="15sp" 
      android:textColor="@color/common_google_signin_btn_text_dark_focused" 
      android:paddingBottom="5dp"/> 
    </LinearLayout> 
</RelativeLayout> 
</ScrollView> 

응답에 대한 감사합니다!

+0

디버그 IT 및 변수'serversArray'가 어떻게이 방법을 사용하지 –

+0

이미이 시도하지 비어 있는지? 부모가없는 뷰를 팽창시키고 ('View vi'), 새롭게 팽창 된 뷰에서 아이들 뷰를 검색 한 다음 모든 것을 버리는 것은 매우 이상합니다. 왜 화면에 추가되지 않은 TextView로 설정된 텍스트를 볼 수있을 것으로 기대하십니까? –

+1

가되어 –

답변

0

의견을 보내 주셔서 감사합니다. 문제가 해결되었습니다!

public void bodAlg() { 
    LayoutInflater inflater = (LayoutInflater) 
    getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View vi = inflater.inflate(R.layout.layout1, null); 

    EditText editText = (EditText) vi.findViewById(R.id.bod_servers); 
    String[] serversArray = editText.getText().toString().split(", "); 

    TextView textView = (TextView) vi.findViewById(R.id.bod_serv_array); 
    textView.setText(Arrays.toString(serversArray)); 

    // solution 
    CoordinatorLayout mainL = (CoordinatorLayout) findViewById(R.id.main_view); 
    mainL.removeAllViews(); // remove previous view, add 2nd layout 
    mainL.addView(vi); 
} 
관련 문제