須自行定義Adapter
public class PriceAdapter extends BaseAdapter { private LayoutInflater myInflater; private ArrayList<PriceObject> mItems = new ArrayList<PriceObject>(); public PriceAdapter(Context context, ArrayList<PriceObject> items) { myInflater = LayoutInflater.from(context); mItems = items; } public void addItem(ArrayList<PriceObject> items) { for (int i = 0; i < items.size(); i++) { mItems.add(items.get(i)); } this.notifyDataSetChanged(); } public int getCount() { return mItems.size(); } public Object getItem(int position) { return mItems.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = myInflater.inflate({list item layout id}, null); } //do something TextView text = (TextView) convertView.findViewById({list item裡的物件ID}); text.setText(mItems.get(position).getXXXX()); return convertView; } }
自行整理好的mPriceObject 設定給 PriceAdapter
adapter再給ListView
PriceAdapter priceAdapter = new PriceAdapter(this, mPriceObject); lvPriceList.setAdapter(priceAdapter);
沒有留言:
張貼留言