Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android textView.setText在复合视图中不工作_Android_Java - Fatal编程技术网

Android textView.setText在复合视图中不工作

Android textView.setText在复合视图中不工作,android,java,Android,Java,textView.setText在复合视图中工作不正常。 意味着hello和jack都出现了。。。 而杰克则显示在布局下方,如果我加上一些背景色,就不会出现,。。。 有人能帮忙吗。。。谢谢和问候 这是我的密码 Layout.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t

textView.setText
在复合视图中工作不正常。 意味着hello和jack都出现了。。。 而杰克则显示在布局下方,如果我加上一些背景色,就不会出现,。。。 有人能帮忙吗。。。谢谢和问候

这是我的密码

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>
试试这个

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");
}

是的,现在我得到了答案。。。实际上,我的构造函数是用这个(上下文)调用的,。。我需要调用super(上下文)


zoneName.setText(“杰克”)超出了方法,您将该行放在“}”之后,将其移动到方法中。不工作意味着zoneName.setText(“jack”);正在设置文本,但它被相对布局的样式覆盖。。。如果背景颜色是给定的,文本就不会出现。实际上,这是一个相对的布局,我必须在这个相对的布局中添加更多的视图。。。这就是为什么我不能将其作为文本视图扩展。
public void setView(){
       mInflater.inflate(R.layout.custom_view, this, true);
       TextView zoneName = (TextView) findViewById(R.id.chatNamed);
       zoneName .setText("jack");
}
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();
    }