如何在Android中将一个tablelayout添加到另一个tablelayout中

如何在Android中将一个tablelayout添加到另一个tablelayout中,android,tablelayout,tablerow,Android,Tablelayout,Tablerow,是否可以在Android Studio中将一个tablelayout添加到另一个tablelayout中? 实际上,我想在一个特定的位置添加一个新行。但当我尝试添加新行时,它总是添加到所有行的下面 你能帮我在安卓工作室做这个吗 注意:它将在运行时工作,我指的是完整的Java代码。 这里是Test2.java类 { int col=4,row=3; 表布局表布局; 编辑文本编辑文本; 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(s

是否可以在Android Studio中将一个tablelayout添加到另一个tablelayout中?
实际上,我想在一个特定的位置添加一个新行。但当我尝试添加新行时,它总是添加到所有行的下面

你能帮我在安卓工作室做这个吗

注意:它将在运行时工作,我指的是完整的Java代码。

这里是Test2.java类

{

int col=4,row=3;
表布局表布局;
编辑文本编辑文本;
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test2);
tableLayout=(tableLayout)findViewById(R.id.table2);
对于(inti=1;i请尝试此代码段

 int index = tableLayout.getChildCount();
        tableRow.setTag(index);

        final Button button = new Button(this);
        button.setText("Add");
        button.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TableRow r = new TableRow(MainActivity.this);

                for (int j = 1; j <= row; j++) {
                    editText = new EditText(MainActivity.this);
                    editText.setTag(editText + String.valueOf(j));
                    editText.setHint("New " + j);
                    editText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
                    editText.setBackground(null);
                    r.addView(editText);
                }


                int index = (Integer)tableRow.getTag();
                System.out.println(index);
                tableLayout.addView(r,(index+1));

            }
        });
        tableRow.addView(button);
        tableLayout.addView(tableRow);
int index=tableLayout.getChildCount();
tableRow.setTag(索引);
最终按钮=新按钮(此按钮);
按钮。设置文本(“添加”);
button.setLayoutParams(新建TableRow.LayoutParams(TableRow.LayoutParams.WRAP_内容,TableRow.LayoutParams.WRAP_内容));
setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
TableRow r=新的TableRow(MainActivity.this);

对于(int j=1;j)为什么不在可扩展的listview中使用tablelayout?请看图片,我认为listview也可以做到这一点,但很难实现“我想在特定位置添加新行”这才是真正的要求,对吗?如果在特定的索引处插入,请使用addview。你是对的。你能推荐一些关于它的教程或示例吗?
 int index = tableLayout.getChildCount();
        tableRow.setTag(index);

        final Button button = new Button(this);
        button.setText("Add");
        button.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TableRow r = new TableRow(MainActivity.this);

                for (int j = 1; j <= row; j++) {
                    editText = new EditText(MainActivity.this);
                    editText.setTag(editText + String.valueOf(j));
                    editText.setHint("New " + j);
                    editText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
                    editText.setBackground(null);
                    r.addView(editText);
                }


                int index = (Integer)tableRow.getTag();
                System.out.println(index);
                tableLayout.addView(r,(index+1));

            }
        });
        tableRow.addView(button);
        tableLayout.addView(tableRow);