2011-09-06 27 views
2

我有2000个记录。我想在tablelayout中显示产品列表。在第一个负载中需要显示50条记录。记录的重新记录需要通过分页显示。Android TableLayout与分页:PRoblem当点击下一个/上一个TableLayout需要重置

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); 当我分析的初始值&终值,将它需要LAOD特别是记录产品清单;

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

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

请帮我

我面临的大问题,对此:

在此先感谢。

回答

3

我想你应该尝试一下这样的,

productList = all products from db 

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

,下一步按钮...

清除TableLayout

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

table.removeAllViews(); 

显示productList中的下一个产品。 (你将在这里有initilend

+1

tl.removeAllViews();工作正常。 – Piraba