1
我有這個適配器顯示從Web服務檢索列表中的項目,滾動它膨脹第一個位置佈局(它考慮第一個可見項目的位置0,這是不正確的),請幫助。在滾動上的基礎適配器位置
這裏是我的適配器:
private class hwListArrayAdapter extends BaseAdapter {
private ArrayList<HomeWork> Items;
private final Activity context;
public hwListArrayAdapter(Activity context, ArrayList<HomeWork> items) {
this.context = context;
this.Items = items;
}
@Override
public int getCount() {
return Items.size() + 1;
}
@Override
public Object getItem(int position) {
return Items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
View v = view;
TextView desc, date, course;
if (position == 0) {
LayoutInflater vi;
vi = LayoutInflater.from(context);
v = vi.inflate(R.layout.homework_list_top, null);
AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) (MyApplication.screenHeight * 0.05));
v.setLayoutParams(params);
} else {
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(context);
v = vi.inflate(R.layout.homework_list_item, null);
}
AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, (int) (MyApplication.screenHeight * 0.6)/8);
v.setLayoutParams(params);
desc = (TextView) v.findViewById(R.id.descriptionHW);
desc.setTypeface(MyApplication.dinar);
desc.setText(Items.get(position - 1).getDetails());
course = (TextView) v.findViewById(R.id.courseHW);
course.setTypeface(MyApplication.dinar);
course.setText(Items.get(position - 1).getCourseName());
date = (TextView) v.findViewById(R.id.dateHW);
date.setTypeface(MyApplication.dinar);
date.setText(dateConverter(Items.get(position - 1).getDueDate()));
}
return v;
}
}
之間總是返回一個值,從而使得如果一樣,如果(getItemViewType(位置)== 0) ?? –
如果你希望你能做到這一點,但在這種情況下不會有太大的區別。但是,一般來說,你應該這樣做 – Blackbelt