我有产品清单。可能包含5000条记录。我把分页。首先加载50条记录。然后如果我们按下一个选项(&gt;)然后同样加载下一个50选项。我设计了表格布局。< / p>
ArrayList<Product> productList = new ArrayList<Product>();
productList = getProducts();
TableLayout tl;
tl = (TableLayout) findViewById(R.id.tableLayout1);
if(productList.size() >0){
for (int i = 0; i < productList.size(); i++) {
TableRow tr = new TableRow(this);
tr.setTag(i);
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=10;
int topMargin=2;
int rightMargin=10;
int bottomMargin=2;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
TextView txtCode = new TextView(this);
TextView txtDes = new TextView(this);
EditText txtQty = new EditText(this);
TextView txtVal = new TextView(this);
TextView txtDisVal = new TextView(this);
TextView txtDisQty = new TextView(this);
txtQty.setId(i);
txtQty.setFocusable(true);
txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
txtQty.setHeight(5);
txtQty.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
createView(tr, txtCode, productList.get(i).getProductCode());
createView(tr, txtDes, productList.get(i).getDescription());
txtQty.setText(Double.toString(productList.get(i).getPrice()));
tr.addView(txtQty);
createView(tr, txtVal,"Value");
createView(tr, txtDisVal,"0.00");
createView(tr, txtDisQty,"0");
tr.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
System.out.println("Row Clicked with tag " + view.getTag());
}
});
tl.addView(tr);
}
}
}
public void createView(TableRow tr, TextView t, String viewdata) {
t.setText(viewdata);
t.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
t.setTextColor(Color.DKGRAY);
t.setPadding(1, 0, 0, 0);
tr.setPadding(0, 0, 0, 0);
tr.addView(t);
}
这是我的实现。我还没有实现分页部分。
如何将其插入内存并加载?
请帮帮我
答案 0 :(得分:1)
我建议您创建一个函数来获取带有param pageindex的产品。 然后,您可以设置由分页事件激活的触发器。 并通过处理程序更新UI