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

前端 未结 4 1390
终归单人心
终归单人心 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:19

    The only difference is the context that you use. If the context that you use with LayoutInflater.fromContext() or context.getSystemService(...) is actually an Activity, it should be equivalent to Activity.getLayoutInflater(). If it's the application object, you might have problems inflating views that contain fragments, IIRC.

提交回复
热议问题