我需要实现这样的事情。我得到了一个项目清单。当用户向下滑动列表时,应滑动显示列表的空项,并应下载另一组项。我该如何实现呢?我有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
答案 0 :(得分:0)
检查尺寸。如果大小为0,则将空视图设置为listview。
listview.setEmptyView(new View(context));