How to display text in a TextView inside a Fragment

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 12:02:40

问题


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

myTextView.setText("Test");

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?


回答1:


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

here is a tutorial for fragments : fragments tutorial



来源:https://stackoverflow.com/questions/16046149/how-to-display-text-in-a-textview-inside-a-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!