这是我的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;
}
}
答案 0 :(得分:2)
而不是
TextView t = (TextView) this.getView().findViewById(R.id.textView1);
你应该在你膨胀的视图上调用findViewById
:
TextView t = (TextView) rootView.findViewById(R.id.textView1);