Prabhu Konchada Prabhu Konchada - 1 year ago 101
Android Question

Unable to inflate a custom view in activity?

I am trying to inflate a custom view in activity onCreateView

LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = inflater.inflate(R.layout.mylayout, null);
TextView text = (TextView)rootView.findViewById(;
text.setText("Hello World");
return rootView;

I am getting stack overflow error

Answer Source

This way I was able to inflate a custom view :)

    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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download