0
테이블에 tablerow를 동적으로 추가해야합니다. 각 행에는 4 개의 TextView가 있어야합니다. 프로그램을 실행할 때 "자식의 부모에게 먼저 removeView를 호출해야합니다."라는 오류가 있습니다. 어떻게해야합니까? 이 내 코드 내 XML입니다 :먼저 부모의 removeView를 호출하십시오.
이@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.post_lineup_sending_layout,
container, false);
tableLayout =(TableLayout)rootView.findViewById(R.id.postsending_table_layout);
ownPlayer = (TextView) rootView.findViewById(R.id.own_player);
pointsOwnPlayer = (TextView) rootView.findViewById(R.id.own_player_points);
enemyPlayer = (TextView) rootView.findViewById(R.id.other_player);
pointsEnemyPlayer = (TextView) rootView.findViewById(R.id.other_player_points);
for(int i=0; i<4; i++){
TableRow tr = new TableRow(CurrentContext.getContext());
ownPlayer.setText("Ciccio");
pointsOwnPlayer.setText(""+6);
enemyPlayer.setText("Avversario");
pointsEnemyPlayer.setText(""+10);
tr.addView(ownPlayer);
tr.addView(pointsOwnPlayer);
tr.addView(enemyPlayer);
tr.addView(pointsEnemyPlayer);
tableLayout.addView(tr);
}
return rootView;
}
XML :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/postsending_table_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow >
<TextView
android:id="@+id/own_player"
android:text="CALCIATORE_0"
android:padding="3dip"
android:layout_width="125dp" />
<TextView
android:id="@+id/own_player_points"
android:text="6"
android:gravity="center"
android:layout_width="30dp" />
<TextView
android:id="@+id/other_player"
android:gravity="center"
android:text="CALCIATORE_1"
android:layout_width="125dp" />
<TextView
android:id="@+id/other_player_points"
android:text="10"
android:gravity="right"
android:layout_width="30dp" />
</TableRow>
</TableLayout>
</LinearLayout>
텍스트 뷰는 동적입니까? – Libin
for 루프에서 텍스트 뷰를 생성해야합니다. – Riser
텍스트 필드의 텍스트가 각 행마다 다릅니다. – Deca