gpt4 book ai didi

具有分页 : Problem When click the Next/previous TableLayout need to reset 的 Android TableLayout

转载 作者:搜寻专家 更新时间:2023-11-01 09:12:26 24 4
gpt4 key购买 nike

我有2000条记录,我想在tablelayout中显示产品列表。第一次加载需要显示50条记录,其余记录需要分页显示。

onCreate() 中我完成了表格布局:它的动态表格内容

   tl = (TableLayout) findViewById(R.id.tableLayout1);
if(productList.size() >0){
if(productList.size() < end){
end = productList.size();
}
Log.i("**onCreate**" , end + "--" + initil);
stk.setText("Stk " + productList.get(0).getAvailableQuantity());
for (int i = initil; i <end; i++) {
Log.i("**i**" ,""+ i);
TableRow tr = new TableRow(this);
tr.setTag(i);
TableLayout.LayoutParams tableRowParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT);
if(i == initil){
selectedProductPrice.setText(Double.toString(productList.get(i).getPrice()));
}
int leftMargin=10;
int topMargin=2;
int rightMargin=10;
int bottomMargin=2;

tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

TextView txtCode = new TextView(this);
txtCode.setTextSize(1, 12);
createView(tr, txtCode, productList.get(i).getProductCode());

TextView txtDes = new TextView(this);
txtDes.setTextSize(1, 12);
createView(tr, txtDes, productList.get(i).getDescription());

EditText txtQty = new EditText(this);
txtQty.setTextSize(2, 12);
txtQty.setHeight(4);
txtQty.setWidth(6);
txtQty.setId(i);
txtQty.setFocusable(true);
txtQty.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
txtQty.setText("0.00");
tr.addView(txtQty);

txtQty.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.v("TAG", "afterTextChanged");
}

public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
Log.v("TAG", "beforeTextChanged");
}

public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.v("TAG", "onTextChanged");
}
});

if(invPriceEdit.equals("") && invPriceEdit.equals("1")){
EditText txtPrice = new EditText(this);
txtPrice.setText(Double.toString(productList.get(i).getPrice()));
txtPrice.setTextSize(1, 12);
txtPrice.setHeight(3);
txtPrice.setWidth(7);
tr.addView(txtPrice);

}else{
TextView txtPrice = new TextView(this);
txtPrice.setTextSize(1, 12);
txtPrice.setText(Double.toString(productList.get(i).getPrice()));
}
Log.i("----" , Double.toString(productList.get(i).getPrice()));
TextView txtVal = new TextView(this);
txtVal.setTextSize(1, 12);
createView(tr, txtVal,"0.00");

TextView txtDisVal = new TextView(this);
txtDisVal.setTextSize(1,12);
createView(tr, txtDisVal,"0.00");

TextView txtDisQty = new TextView(this);
txtDisQty.setTextSize(1, 12);
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);
}

onNextAction()方法我做了分页

  public void onNextProductAction(View view) {
int tmp = productList.size();
Button next = (Button) findViewById(R.id.next);
if(end < tmp){
end = end +10;
initil = initil +10;
if(end > tmp ){
end = productList.size() - initil;
next.setEnabled(false);
}
}else{
end = productList.size() - initil;
next.setEnabled(false);
}
Log.i("**onNextProductAction**" , "--" + end + "----" + initil);
}

问题是当我点击下一步按钮时,TableLaout 需要重置内容。

这意味着我使用 productList = getProducts(altSearch,productCate,productGroup,productType); 获得了产品列表;当我解析初始值和结束值时,它需要加载特定的记录;

当我点击下一个选项时,它将记录与以前的记录附加在一起。

我只想显示下一条可用记录。

最佳答案

我觉得你应该这样试试,

productList = all products from db

在 TableLayout 的第一页显示所需的产品

现在,在 Next 按钮上...

清除表格布局

int count=table.getChildCount();
for(int i=0;i<count;i++)
table.removeView(layout.getChildAt(i));

 table.removeAllViews();

显示 productList 中的下一个产品。 (您将在此处拥有 initilend)

关于具有分页 : Problem When click the Next/previous TableLayout need to reset 的 Android TableLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7315073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com