Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在onClick中添加动态滚动视图_Java_Android - Fatal编程技术网

Java 如何在onClick中添加动态滚动视图

Java 如何在onClick中添加动态滚动视图,java,android,Java,Android,我创建了一个表格行,如果我单击网格项,它将显示该表格行,并且我需要该表格行可滚动 我想在表行的代码中添加一个动态滚动视图,但是当我使用onclick时它崩溃了,有人能帮我解决这个错误吗 “java.lang.IllegalStateException:指定的子级已具有 父级。必须首先对子级的父级调用removeView() gridView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){ @凌驾 公共链接(AdapterVi

我创建了一个表格行,如果我单击网格项,它将显示该表格行,并且我需要该表格行可滚动

我想在表行的代码中添加一个动态滚动视图,但是当我使用
onclick
时它崩溃了,有人能帮我解决这个错误吗

“java.lang.IllegalStateException:指定的子级已具有 父级。必须首先对子级的父级调用removeView()

gridView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
公共链接(AdapterView arg0、视图arg1、内部arg2、,
长arg3){
//TODO自动生成的方法存根
//结果tr
TableRow tr_head2=新的TableRow(GridDynamic.this);
tr_head2.setId(10);
tr_head2.setBackgroundDrawable(getResources().getDrawable(R.drawable.fab_label_background));
tr_头2.设置填充(10,10,10,10);
tr_head2.setLayoutParams(新的TableLayout.LayoutParams(
TableLayout.LayoutParams.FILL\u父级,
TableLayout.LayoutParams.FILL_PARENT);
TextView label_category2=新的TextView(GridDynamic.this);
标签2.setId(20);
标签2.setText(“1”);
标签2.setTextColor(颜色为黑色);
label_category2.setTypeface(null,Typeface.BOLD_ITALIC);
标签2.SettexSize(18);
标签2.设置填充(20,3,20,3);
tr_head2.addView(label_category2);//在此处将列添加到表行中
TextView标签\数量\数量2=新的TextView(GridDynamic.this);
label_quantity_amount2.setId(21);//定义必须唯一的id
label_quantity_amount2.setText(alphabets.get(arg2.get(“Name”).toString());//设置标题的文本
label_quantity_amount2.setTextColor(Color.BLACK);//设置颜色
标签\数量\数量2.设置字体(空,字体.粗体\斜体);
标签\数量\数量2.设置尺寸(18);
label_quantity_amount2.setPadding(20,3,20,3);//设置填充(如果需要)
tr_head2.addView(label_quantity_amount2);//在此处将列添加到表行中
TextView标签\总价\金额2=新的TextView(GridDynamic.this);
label_total_price_amount2.setId(22);//定义必须唯一的id
label_total_price_amount2.setText(alphabets.get(arg2.get(“price”).toString());//设置标题的文本
label_total_price_amount2.setTextColor(Color.BLACK);//设置颜色
标签\总价\金额2.设置字体(空,字体,粗体\斜体);
标签总价格金额2.SettexSize(18);
label_total_price_amount2.设置填充(20,3,20,3);//设置填充(如果需要)
tr_head2.addView(label_total_price_amount2);//在此处将列添加到表行中
tableLayout.addView(tr_head2,新的tableLayout.LayoutParams(
TableLayout.LayoutParams.FILL\u父级,
TableLayout.LayoutParams.WRAP_CONTENT);
ScrollView scroll=新的ScrollView(GridDynamic.this);
scroll.setLayoutParams(新建TableRow.LayoutParams(TableRow.LayoutParams.FILL\u父级,
TableRow.LayoutParams.FILL_PARENT);
scroll.addView(tr_head2);
Toast.makeText(getBaseContext(),alphabets.get(arg2.get)(“Item_ID”).toString()+
“”+alphabets.get(arg2.get(“Name”).toString()+
“”+alphabets.get(arg2.get(“Price”).toString(),
吐司。长度(短)。show();
}
});

您的代码中似乎有两个
addView
具有相同的参数
tru head2
,这可能是原因

您的代码中似乎有两个
addView
具有相同的参数
tru head2
,这可能是原因所在

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                // TODO Auto-generated method stub
                //Result tr
                TableRow tr_head2 = new TableRow(GridDynamic.this);
                tr_head2.setId(10);
                tr_head2.setBackgroundDrawable(getResources().getDrawable(R.drawable.fab_label_background));
                tr_head2.setPadding(10, 10, 10, 10);
                tr_head2.setLayoutParams(new TableLayout.LayoutParams(
                        TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.FILL_PARENT));

                TextView label_category2 = new TextView(GridDynamic.this);
                label_category2.setId(20);
                label_category2.setText("1");
                label_category2.setTextColor(Color.BLACK);
                label_category2.setTypeface(null, Typeface.BOLD_ITALIC);
                label_category2.setTextSize(18);
                label_category2.setPadding(20, 3, 20, 3);
                tr_head2.addView(label_category2);// add the column to the table row here

                TextView label_quantity_amount2 = new TextView(GridDynamic.this);
                label_quantity_amount2.setId(21);// define id that must be unique
                label_quantity_amount2.setText(alphabets.get(arg2).get("Name").toString()); // set the text for the header
                label_quantity_amount2.setTextColor(Color.BLACK); // set the color
                label_quantity_amount2.setTypeface(null, Typeface.BOLD_ITALIC);
                label_quantity_amount2.setTextSize(18);
                label_quantity_amount2.setPadding(20, 3, 20, 3); // set the padding (if required)
                tr_head2.addView(label_quantity_amount2); // add the column to the table row here

                TextView label_total_price_amount2 = new TextView(GridDynamic.this);
                label_total_price_amount2.setId(22);// define id that must be unique
                label_total_price_amount2.setText(alphabets.get(arg2).get("Price").toString()); // set the text for the header
                label_total_price_amount2.setTextColor(Color.BLACK); // set the color
                label_total_price_amount2.setTypeface(null, Typeface.BOLD_ITALIC);
                label_total_price_amount2.setTextSize(18);
                label_total_price_amount2.setPadding(20, 3, 20, 3); // set the padding (if required)
                tr_head2.addView(label_total_price_amount2); // add the column to the table row here

                tableLayout.addView(tr_head2, new TableLayout.LayoutParams(
                        TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT));

                ScrollView scroll = new ScrollView(GridDynamic.this);
                scroll.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                        TableRow.LayoutParams.FILL_PARENT));
                scroll.addView(tr_head2);

                Toast.makeText(getBaseContext(), alphabets.get(arg2).get("Item_ID").toString()+
                                " "+alphabets.get(arg2).get("Name").toString()+
                        " "+alphabets.get(arg2).get("Price").toString(),
                        Toast.LENGTH_SHORT).show();
            }
        });