Prabhu Konchada Prabhu Konchada - 5 months ago 22
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(R.id.text_view);
text.setText("Hello World");
return rootView;



I am getting stack overflow error

Answer

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

 @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;
    }
Comments