Is there any difference between getLayoutInflater() and .getSystemService(Context.LAYOUT_INFLATER_SERVICE)

前端 未结 4 699
无人共我
无人共我 2020-12-08 20:09

Simple \"No\" answer will calm me. If there is any difference then what it is?

4条回答
  •  一生所求
    2020-12-08 20:30

    There is at least one situation that only

    getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    must be used instead of the counterpart

    getLayoutInflater

    That situation is in an arbitrary object class. For example, I have an instance of class call objectA. In objectA, I want to inflate a view onto the parent view (happen in ArrayAdapter that inflates customized row on the its listview.) In this case, context.getLayoutInflater does not work since there is no activity or windows associated with the context. Only getSystemService(Context.LAYOUT_INFLATER_SERVICE) is appropriate then.

提交回复
热议问题