What is the correct way to get layout inflater in Android?

前端 未结 4 1404
终归单人心
终归单人心 2021-01-30 21:47

There is a way to get layoutInflater:

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

and

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 22:06

    There is not much of a difference between them.

    As doc says public abstract Object getSystemService (String name)

    A LayoutInflater for inflating layout resources in this context.

    And for the public static LayoutInflater from (Context context)

    Obtains the LayoutInflater from the given context.

    You can check this thread Is there any difference between getLayoutInflater() and .getSystemService(Context.LAYOUT_INFLATER_SERVICE)

提交回复
热议问题