无法在活动中夸大自定义视图?

时间:2016-06-12 13:12:04

标签: android

我正在尝试在活动onCreateView

中充气自定义视图
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View rootView = inflater.inflate(R.layout.mylayout, null);
    TextView text = (TextView)rootView.findViewById(R.id.text_view);
    text.setText("Hello World");
    return rootView;
  

我收到堆栈溢出错误

1 个答案:

答案 0 :(得分:0)

通过这种方式,我可以扩充自定义视图:)

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View layout = inflater.inflate(R.layout.fragment_hello_world, container, false);
        return layout;
    }