2011-09-06 6 views
2

나는 2000 레코드가 있습니다. 나는 tablelayout에 제품의 목록을 보여주고 싶습니다. fisrst로드 50 레코드를 표시해야합니다. 페이지 매김을 통해 보여줍니다.페이지 설정 안드로이드 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); 
     } 

내가 매김를 재설정해야 내가 다음 버튼 TableLaout을 클릭하면 문제가

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); 
    } 

했다 onNextAction() 방법 내용. 내가 초기 값 & 끝 값을 구문 분석 할 때, 그것은 기록을 특정 laod 것을해야합니다 productList = getProducts(altSearch,productCate,productGroup,productType); 를 사용하여 제품의 목록을 가지고 의미

;

다음 옵션을 클릭하면 이전 레코드가있는 레코드가 첨부됩니다.

다음 사용 가능한 레코드 만 표시하고 싶습니다.

사전에 감사 :

나는이에 대한 큰 문제에 직면하고 도와주세요. 난 당신이 이런 식으로 시도해야한다고 생각

답변

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

관련 문제