错误java.lang.IllegalStateException:指定的子级已有父级。您必须首先在孩子的父母上调用removeView()

时间:2017-02-19 11:30:44

标签: java android

我想在onClick中向tablerow添加一个滚动视图我已经有了代码但它崩溃了不幸的是,已经停止了java.lang.IllegalStateException:指定的子节点已经有了一个父节点。我刚刚单击该项目时创建了一个GridView GridView它用行显示这个表格布局,这是我的onClick代码

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                long arg3) {
            // TODO Auto-generated method stub
            //Result tr
            String st = "insert into ChecksItems (Check_ID,Item_ID,QTY,UnitPrice,TotalPrice,DicountValue,Tax_Value,Adj_Value,NetPrice,Serial,Fired,Fired_Time,Voided,Voided_Time,Voided_Reason,P_On_Check,Complement,Status,IsModifier,Ref_Mod_Item,IsAssimbly,Ref_Ass_Item,Taxable,NoServiceCharge,Num_Fired,Num_Print,Server_ID,P_On_Report,Check_ID_Combine,Round_Check_Fired,Void_Effect_Invn,Promo_ID,Orig_Price,Officer,Comp_Reason_ID,End_Serial_Count,Discount_ID,Disc_Reason_ID,Hold,Hold_Time,Voided_By,Comp_By,Disc_By) values (" + String.valueOf(MenuListView.Check_ID) + "," + alphabets.get(arg2).get("Item_ID").toString() + ",1," + alphabets.get(arg2).get("Price").toString() + "," + alphabets.get(arg2).get("Price").toString() + ",0,0,0," + alphabets.get(arg2).get("Price").toString() + "," + String.valueOf(MenuListView.Item_Serial) + ",0,GetDate(),0,GetDate(),0,'" + alphabets.get(arg2).get("PrintOnChick").toString() + "',0,'New',0,0,0,0,'" + alphabets.get(arg2).get("Taxable").toString() + "','" + alphabets.get(arg2).get("NoServiceCharge").toString() + "',0,0,0,'" + alphabets.get(arg2).get("PrintOnReport").toString() + "',0,1,0,0," + alphabets.get(arg2).get("Price").toString() + ",0,0,0,0,0,0,GetDate(),0,0,0)";

            if (ConnectionClass.executeUpdate(st)) {
                MenuListView.Item_Serial++;
                final 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);
            scroll.removeAllViews();
            }

        }
    });

0 个答案:

没有答案