如何显示一个片段里面一个TextView文本

如何显示一个片段里面一个TextView文本

问题描述:

似乎是一个简单的问题给我,但我不能弄明白。我有这个code我里面的片段:

Seems like a simple question to me, but I can't figure it out. I have this code inside my Fragment:

myTextView.setText("Test");

不过,这code刹车我的应用程序,而且我不确定为什么。也许这是一个意见冲突,但我还是不明白为什么它不会工作。有什么建议?

However, this code brakes my app and I am unsure why. Perhaps this is a conflict with Views, but I still don't understand why it wont work. Any suggestions?

你是怎么设置的内容?

How did you set the content?

编辑我的答案:)试试这个

Edited my answer :) try this

 @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.xmlName,
        container, false);
    TextView tv= (TextView) **view**.findViewById(R.id.textViewName);
    tv.setText("yourText"); 
    return view;
  }

下面是片段教程:片段教程