2014-12-23 3 views
0

textView.setText이 복합보기에서 제대로 작동하지 않습니다. 수단 모두 ... 안녕하세요 내가 ... 누군가가 ... 감사합니다 도움이 될 몇 가지 배경 색상을 넣어 관해서 경우 잭 레이아웃이 표시되지 아래에 표시됩니다 ... 와 잭이 나타나고있다복합보기에서 textView.setText가 작동하지 않습니다.

다음

가 내 코드 ...

Layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/chatLayout" 
      android:layout_width="300dp" 
      android:layout_height="400dp" 
      > 

      <TextView 
       android:id="@+id/chatNamed" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="Hello" 
       android:textColor="#ffffff" 
       android:textSize="20dp" 
       android:textStyle="bold" 
       android:layout_marginTop="10dp" 
       android:layout_marginLeft="10dp" 
       /> 


     </RelativeLayout> 

CompoundView.java

+1

'zoneName.setText ("jack"); "}"다음에 행을 이동합니다. –

답변

0

그래 지금은 사실 내 생성자이 (컨텍스트)를 호출하는 대답을 ... 있어요 .. 슈퍼 (컨텍스트)를 호출해야합니다 ...

Code Changed to 
public ChatCompoundView(Context context) { 
     super(context); 
     setView(); 

    } 
    public ChatCompoundView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     setView(); 

    } 
    public ChatCompoundView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
      setView(); 
    } 
0

이 시도 ..

LayoutInflater mInflater; 
public ChatCompoundView (Context context) { 
    super(context); 
    mInflater = LayoutInflater.from(context); 
    setView(); 

} 

setView를() :

public void setView(){ 
     mInflater.inflate(R.layout.custom_view, this, true); 
     TextView zoneName = (TextView) findViewById(R.id.chatNamed); 
     zoneName .setText("jack"); 
} 
+0

작동하지 않음 zoneName.setText ("jack"); 텍스트를 설정하고 있지만 상대 레이아웃의 스타일로 덮여 있습니다 ... 그리고 배경색이 주어지면 텍스트가 나타나지 않습니다. –

+0

'textView'를 확장하고 시도해보십시오. 내 편집 된 ans도 확인하십시오. –

+0

실제로 상대 레이아웃과 저는 그 상대적인 레이아웃에 좀 더 많은 의견을 넣어 봤는데 ... 그게 내가 왜 textview 연장으로 만들 수 없습니다. –

관련 문제