这次总结下拉刷新
以这个为例子吧。
先写列表的model和adapter.
model多独立写写,写多了就熟练了。
public class MyorderReceiveInfo implements Serializable {
private int id;
private String logo;
private String subname;
private String smallname;
private int rating;
private String price;
private String pay;
private String receive;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public String getSubname() {
return subname;
}
public void setSubname(String subname) {
this.subname = subname;
}
public String getSmallname() {
return smallname;
}
public void setSmallname(String smallname) {
this.smallname = smallname;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public String getPrice() {
return price;
}
public void setPay(String pay) {
this.pay = pay;
}
public String getPay() {
return pay;
}
public void setReceive(String receive) {
this.receive = receive;
}
public String getReceive()
{
return receive;
}
public MyorderReceiveInfo(String subname,String smallname, int rating, String price,String pay,String receive) {
super();
this.subname = subname;
this.smallname = smallname;
this.rating = rating;
this.price = price;
this.pay = pay;
this.receive = receive;
}
public static List<MyorderReceiveInfo> getTest(){
List<MyorderReceiveInfo> list = new ArrayList<MyorderReceiveInfo>();
MyorderReceiveInfo test1 = new MyorderReceiveInfo("科目二","向师傅", 3, "3000元", "待接收","接收");
MyorderReceiveInfo test2 = new MyorderReceiveInfo("科目一","向师傅", 3, "3000元", "已接收","接收");
MyorderReceiveInfo test3 = new MyorderReceiveInfo("科目三","向师傅", 3, "3000元", "待接收","接收");
list.add(test1);
list.add(test2);
list.add(test3);
return list;
}
}
Adapter也比较常规格式,但是里面要注意的细节比较多。刚接触的时候写了好多遍
public class MyorderReceiveAdapter extends BaseAdapter{
private List<MyorderReceiveInfo> mMyorderList;
private LayoutInflater minflater;
// Context context;
public MyorderReceiveAdapter(Context context, List<MyorderReceiveInfo> myorderList)
{
mMyorderList = myorderList;
minflater = LayoutInflater.from(context);
//this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
if(mMyorderList == null)
{
return 0;
}else
{
return mMyorderList.size();
}
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if(convertView == null)
{
holder = new ViewHolder();
convertView = minflater.inflate(R.layout.myorderreceive_item, null);
//convertView = minflater.inflate(R.layout.myorder_item, null);
holder.tv_subname = (TextView)convertView.findViewById(R.id.tv_bname);
holder.tv_sname = (TextView)convertView.findViewById(R.id.tv_sname);
holder.tv_price = (TextView)convertView.findViewById(R.id.tv_price);
holder.tv_pay = (TextView)convertView.findViewById(R.id.tv_pay);
holder.bt_receive =(Button)convertView.findViewById(R.id.bt_evaluate);
holder.rb_rating =(RatingBar)convertView.findViewById(R.id.rb_rating);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.tv_subname.setText(mMyorderList.get(position).getSubname());
holder.tv_sname.setText(mMyorderList.get(position).getSmallname());
holder.tv_price.setText(mMyorderList.get(position).getPrice());
holder.tv_pay.setText(mMyorderList.get(position).getPay());
holder.rb_rating.setRating(mMyorderList.get(position).getRating());
holder.bt_receive.setText(mMyorderList.get(position).getReceive());
return convertView;
}
public class ViewHolder
{
public TextView tv_subname;
private TextView tv_sname;
private TextView tv_price;
private TextView tv_pay;
private RatingBar rb_rating;
private Button bt_receive;
}
}