2014-04-24 4 views
0
public void populate() { 

     TableRow tr = new TableRow(getActivity()); 

     tr.setId(100 + count); 
     tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 

     Button b_add = new Button(getActivity()); 
     b_add.setId(20); 
     b_add.setText("+"); 
     b_add.setTextColor(Color.RED); 
     b_add.setGravity(Gravity.CENTER); 
     b_add.setPadding(2, 2, 2, 2); 
     b_add.setOnClickListener(add); 

     tr.addView(b_add); 

     TextView v_no = new EditText(getActivity()); 
     v_no.setId(200 + count); 
     v_no.setHint("Vehicale NO"); 
     v_no.setTag("adress"); 
     v_no.setTag("v_no"); 
     v_no.setTextColor(Color.BLACK); 
     v_no.setGravity(Gravity.CENTER); 
     tr.addView(v_no); 

     Button b_minus = new Button(getActivity()); 
     b_minus.setId(20); 
     b_minus.setText("-"); 
     b_minus.setTextColor(Color.RED); 
     b_minus.setGravity(Gravity.CENTER); 
     b_minus.setPadding(2, 2, 2, 2); 
     b_minus.setOnClickListener(remove); 
     tr.addView(b_minus); 
     // finally add this to the table row 
     tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 
     count++; 
    } 

테이블 레이아웃을 사용하여 세 개의 열로 테이블을 생성하려면이 코드를 작성하십시오. 첫 행을 제외하고 테이블 행을 제거해야합니다. (제거되지 않습니다) 하나가 남을 때까지첫 번째 테이블 행을 제외하고 테이블 행을 제거하십시오

답변

1
while (yourTableLayout.getChildCount() > 1) 
    yourTableLayout.removeView(yourTableLayout.getChildAt(yourTableLayout.getChildCount() - 1); 

것을이, 당신의 TableLayout 반복하고 행을 아래에서 위로 하나씩 제거해야 않습니다.

관련 문제