[英]How can I change a Fragment text?
這是我的Fragment
類,我在xmlfile中有一個textView
如何通過setText更改TextView
?
public class Frist extends Fragment {
TextView text;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_frist, container, false);
TextView t = (TextView) this.getView().findViewById(R.id.textView1);
t.setText("SOME TEXT");
return rootView;
}
}
代替
TextView t = (TextView) this.getView().findViewById(R.id.textView1);
您應該在膨脹的視圖上調用findViewById
:
TextView t = (TextView) rootView.findViewById(R.id.textView1);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.