0

我需要实现这样的事情。我得到一个项目清单。当用户向下滑动列表时,应该滑动显示列表的空项目,并且应该下载另一组项目。我该如何实施?我有 ArrayAdapter 类:

public class OrderAdapter extends ArrayAdapter<Order>{


    Context context; 
    int layoutResourceId;    
    List<Order> orders = null;

    public OrderAdapter(Context context,  int layoutResourceId,List<Order> orders) {
        super(context, layoutResourceId, orders);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.orders = orders;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        OrderHolder holder = null;

        if(row == null)
        {
            Log.i("I'm in OrderAdapter",Integer.toString(layoutResourceId));


            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(R.layout.dash_alt_item, parent, false);

            holder = new OrderHolder();
            holder.orderId = (TextView)row.findViewById(R.id.altOrderId);
            holder.orderTitle = (TextView)row.findViewById(R.id.altOrderTitle);
            holder.orderStatus = (TextView)row.findViewById(R.id.altOrderStatus);
            holder.orderPrice = (TextView)row.findViewById(R.id.altOrderPrice);

            row.setTag(holder);
        }
        else
        {
            holder = (OrderHolder)row.getTag();
        }

        Order order = orders.get(position);
        Log.i("id",Integer.toString(order.getOrderid()));
        holder.orderId.setText(Integer.toString(order.getOrderid()));
        holder.orderTitle.setText(order.getTitle());
        holder.orderStatus.setText(order.getProcess_status().getProccessStatusTitle());
        holder.orderPrice.setText(Float.toString(order.getPrice()));


        return row;
    }

    static class OrderHolder
    {
        TextView orderId;
        TextView orderTitle;
        TextView orderStatus;
        TextView orderPrice;
    }
}

这就是我下载项目的方式:

    private class DownloadTask extends AsyncTask<String, Void, List<Order> > {
            protected List<Order>  doInBackground(String... args) {

            try {
                DashboardActivityAlt.this.getOrderList(Integer.toString(DashboardActivityAlt.page), Integer.toString(DashboardActivityAlt.perpage));


            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


                return forPrint;

            }

            protected void onPostExecute(List<Order>  forPrint) {


                DashboardActivityAlt.this.listView1 = (ListView)findViewById(R.id.altOrderslist);
                OrderAdapter adapter = new OrderAdapter(DashboardActivityAlt.this, R.layout.dash_alt_item, forPrint);

                listView1.setAdapter(adapter);

                if (DashboardActivityAlt.this.pd != null) {

                    DashboardActivityAlt.this.pd.dismiss();
                }

            }
       }

我尝试添加 Order 类的空项,但得到 NullPointerException

4

1 回答 1

0

检查尺寸。如果大小为 0,则将空视图设置为列表视图。

 listview.setEmptyView(new View(context));
于 2012-09-14T14:00:26.813 回答