正常充气:
lvStudents = (ListView) findViewById(R.id.lvStudent);
adapter = new StudentAdapter(this, biz.getStudents());
lvStudents.setAdapter(adapter);
lvData = (ListView) findViewById(R.id.lvData);
adapter = new ConversationAdapter(this, biz.getConversations());
lvData.setAdapter(adapter);
特殊充气:
//CallLogListAdapter getView()方法中充气如下:
if (convertView == null) {
// 注意是充气是mItemLayoutResId,那就具体是在CallLogFragment中的onCreateView中充气的.
convertView = mLayoutInflater.inflate(mItemLayoutResId, null);
}
//CallLogFragment中具体充气成功如下:
List<ContactBean> contactListData = new ArrayList<ContactBean>();
mContactsListAdapter = new ContactsListAdapter(getActivity(),contactListData, R.layout.contacts_list_item_layout);
mContactsListView.setAdapter(mContactsListAdapter);
listview显示数据三种方式:
1:changeData
StuMainActivity类中:
private void setupView() {
lvStudents = (ListView) findViewById(R.id.lvStudents);
adapter = new StudentAdapter(this, null);
lvStudents.setAdapter(adapter);
}
StudentAdapter类中:
public void setStudents(ArrayList<Student> students) {
if (students != null)
this.students = students;
else
this.students = new ArrayList<Student>();
}
public StudentAdapter(Context context, ArrayList<Student> students) {
this.setStudents(students);
this.inflater = LayoutInflater.from(context);
}
adapter.changeData(biz.getStudents());
2:util
MainActivity类中:
private void setupView() {
this.lv1 = (ListView) findViewById(R.id.lv1);
this.productService = new ProductService();
List<Product> list = this.productService.findAll();
this.adapter = new ProductAdapter(list, LayoutInflater.from(this));
lv1.setAdapter(adapter);
}
ProductAdapter类中:
public ProductAdapter(List<Product> list,LayoutInflater inflater) {
this.list = list;
this.inflater = inflater;
}
3:application
FSPointActivity类中:
user = MyApplication.getMyApplication().getUser();
private void setupView() {
keywords = user.getCustomKeywords();
adapter = new PointsAdapter(this, keywords);
gvPoints.setAdapter(adapter);
}
PointsAdapter类中:
public void setKeywords(ArrayList<CustomKeyword> keywords) {
if (keywords != null) {
this.keywords = keywords;
} else {
this.keywords = new ArrayList<CustomKeyword>();
}
}
public PointsAdapter(Context context, ArrayList<CustomKeyword> keywords) {
this.context = context;
this.inflater = LayoutInflater.from(context);
this.setKeywords(keywords);
}