版權聲明:本文爲博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/mpt_android/article/details/49048761
今天遇到的問題。Activity向Fragment傳遞數據時,要注意的問題:在Fragment中用於顯示Activity傳遞過來的數據的組件在findViewById時要寫 在onCreateView方法中,不然會有錯。如寫成
<span style="font-size:18px;"> public class Fragment01 extends Fragment{
TextView tv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = View.inflate(getActivity(), R.layout.fragment01,null);
tv = (TextView) v.findViewById(R.id.tv);
return v;
}
public void setText(String text){
tv.setText(text);
}
}
</span>