其他分享
首页 > 其他分享> > android – getLayoutInflator和(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)之间的区别

android – getLayoutInflator和(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE)之间的区别

作者:互联网

我对这两个陈述感到困惑.
有什么区别,什么时候可以使用每一个?

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.activity_custom_lists1, parent);

View v =  getLayoutInflater().inflater.inflate(R.layout.activity_custom_lists1, parent);

解决方法:

第二个是错的

View v =  getLayoutInflater().inflater.inflate(R.layout.activity_custom_lists1, parent);

有可能

View v =  getLayoutInflater().inflate(R.layout.activity_custom_lists1, parent);

second one is called for the activity scope and the first one can be called from outside the Activity with the context

标签:android,android-layout,android-view,layout-inflater
来源: https://codeday.me/bug/20190620/1244460.html