總結的來說,inflate方法獲得佈局,findViewById方法獲得佈局下的控件
在活動類中,直接使用findViewById(),是獲得指定佈局(setContentView()設置的佈局)下的控件
在非活動類中使用inflate方法獲得佈局
先獲取LayoutInflater對象:
LayoutInflater mInflater=LayoutInflater.from(this);//LayoutInflater.from(getContext());
bView=mInflater.inflate(R.layout.XX_item,null);
或者直接
bView=LayoutInflater.from(this).inflate(R.layout.XX_item,null);
得到佈局,我們就可以用bView.findViewById()得到相應佈局文件裏的某些控件。
例如:
TextView textView=(TextView) bView.findViewById(R.id.text_View);
textView.setText......