解析 getLayoutInflater 时出错(未定义)

2024-02-27

当我使用以下代码编译程序时,发生错误。它说 getLayoutInflater () 未定义。我该如何解决?

 final LayoutInflater inflater = getLayoutInflater ( ); 

嗨,Prasanth,你可以试试这个

步骤 1:为 Layout Inflater 创建一个对象,如下所示:

LayoutInflater mInflater;

Step2:通过传递Context进行初始化

Context context=MyActivity.getApplicationContext();
mInflater = LayoutInflater.from(context);

Step3:在getView方法中,您可以将视图初始化为

public View getView(int arg0, View myView, ViewGroup parent) {


            if (convertView == null) {

myView = mInflater.inflate(R.layout.mytest, null);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

解析 getLayoutInflater 时出错(未定义) 的相关文章

随机推荐