永发信息网

android spinner自定义适配器怎么添加头部

答案:2  悬赏:0  手机版
解决时间 2021-02-13 23:16
  • 提问者网友:辞取
  • 2021-02-13 19:02
android spinner自定义适配器怎么添加头部
最佳答案
  • 五星知识达人网友:封刀令
  • 2021-02-13 20:38
自定义适配器中LayoutInflater的使用
在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById()。不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例化;而findViewById()是找xml布局文件下的具体widget控件(如Button、TextView等)。
具体作用:
1、对于一个没有被载入或者想要动态载入的界面,都需要使用LayoutInflater.inflate()来载入;
2、对于一个已经载入的界面,就可以使用Activiyt.findViewById()方法来获得其中的界面元素。
使用LayoutInflater有两种方法:
方法一:
[java] view plain copy
private LayoutInflater listContainer ; // 视图容器
listContainer = LayoutInflater. from (context); // 创建视图容器并设置上下文
convertView = listContainer .inflate(R.layout. list_item , null ); // 获取list_item布局文件的视图
方法一:
[java] view plain copy
private LayoutInflater inflater ;
inflater = (LayoutInflater) context.getSystemService(Context. LAYOUT_INFLATER_SERVICE );
convertView = inflater .inflate( R.layout. list_item , null ); //生成条目界面对象
全部回答
  • 1楼网友:梦中风几里
  • 2021-02-13 21:31
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯