0

我有一个包含很多字段的表单。在调用一个新的 Intent(相机)并返回主活动后,所有字段都被填充。好的。

但是 tablelayout 失去了内部 TableRows。为什么?有没有办法保留tablerows?

tableMaterialObra = (TableLayout)findViewById(R.id.tlMaterialObra);
TableRow tr = new TableRow(this);
CheckBox cb = new CheckBox(this);
tr.addView(cb);
tableMaterialObra.addView(tr);
4

1 回答 1

0

如果您在 oncreate() 方法中创建 TableLayout 而在 onResume() 方法中不执行任何操作,则不会丢失任何行

示例代码

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class RelativeLayoutTesting extends ActivityGroup implements OnClickListener{
    TextView choosenGroup;
    android.widget.RelativeLayout currentView = null;
    ArrayList<String> logpoint = null;
    TableLayout tableMaterialObra;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );


        // set the relative layout as our view 
        setContentView(R.layout.my_table);
        tableMaterialObra = (TableLayout)findViewById(R.id.my_table);
        TableRow tr = new TableRow(this);
        tr.setBackgroundColor(Color.WHITE);
        CheckBox cb = new CheckBox(this);
        tr.addView(cb);
        tableMaterialObra.addView(tr);
        LinearLayout myLayout = (LinearLayout) findViewById(R.id.my_layout);
        myLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        startActivity(new Intent(RelativeLayoutTesting.this, com.sunil.MyListView.class));
    }

}
于 2011-12-28T06:03:46.750 回答