如何快速获取ListView的打气筒对象

简单的方式有三种:

 @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view;
            if (convertView == null) {
                // 获取打气筒的三种方式
                // 方式一:
                // view = View.inflate(getApplicationContext(), R.layout.item, null);

                // 方式二:
                // view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item, null);

                // 方式三:
                LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
                view = inflater.inflate(R.layout.item, null);
            } else {
                view = convertView;
            }

            return view;
        }

 

posted @ 2018-11-21 22:00  远近啊  阅读(202)  评论(0编辑  收藏  举报