What is the difference between calling LayoutInflater directly and not?

前端 未结 2 1694
谎友^
谎友^ 2021-02-14 22:44

I went through some tutorials, and in the Android Doc, it says not to access LayoutInflater directly when instantiating it. Example from the google Doc:

LayoutIn         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-14 23:05

    LayoutInflater inflater = (LayoutInflater)context.getSystemService
      (Context.LAYOUT_INFLATER_SERVICE);
    

    You are getting LayoutInflater Service Provider from System Manager

    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    

    You are using static method from LayoutInflater Class

    I would say that difference is only in code and how you write this also calling stack but result is same - you will get LayoutInflater.

    More about this

    Regards

提交回复
热议问题