机器人TableLayout与分页:问题当单击Next / previous TableLayout需要重置 [英] Android TableLayout with pagination: PRoblem When click the Next/previous TableLayout need to reset

查看:314
本文介绍了机器人TableLayout与分页:问题当单击Next / previous TableLayout需要重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2000 records.I想展示的产品列表中tablelayout.In的fisrst负载需要显示50 records.Rest的记录需要通过分页显示。

I have 2000 records.I want to show list of products in tablelayout.In the fisrst load need to show 50 records.Rest of the records need to show through pagination.

的onCreate()我已经做表格布局:它的动态目录

In onCreate() i have done table Layout: Its Dynamic Table contents

   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需要重新设置内容。

The problem is When I click the next button TableLaout need to reset the contents.

这意味着我得到了使用产品列表产品=的getProducts(altSearch,productCate,productGroup,productType); 当我分析的初始值和放大器;结束值,则它将需要LAOD特定的记录;

That means I got list of products using productList = getProducts(altSearch,productCate,productGroup,productType); When I parse the initial value & end value, The it will need to laod particular that records;

当我点击它旁边附上previous记录的记录选项。

When I click next option it attached the records with previous records.

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

I want to show only next available records only.

请帮我

我就面临这个大问题:

在此先感谢。

推荐答案

我想你应该尝试像这样,

I think you should try it like this,

productList = all products from db

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

Show the required products on first page in TableLayout

现在,下一步按钮...

Now, on Next Button...

清除TableLayout

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

 table.removeAllViews();

从显示的产品列表下一个产品。 (你将有这里 initil 结束

这篇关于机器人TableLayout与分页:问题当单击Next / previous TableLayout需要重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆