2017-02-14 11 views
0

グリッドアイテムをクリックすると、このテーブルの行が表示され、このテーブルの行がスクロール可能なテーブル行が作成されました。onClickで動的スクロールビューを追加する方法

私はテーブルの行でこのコードでダイナミックなスクロールビューを追加したいが、それは私がonclickを使用する場合、このエラーが

「java.lang.IllegalStateExceptionであるため、いずれかが私を助けてもらえ墜落しました:指定された子には既に の親があります。最初にその子の親に対してremoveView()を呼び出す必要があります。

 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(); 
      } 
     }); 

答えて

0

2つのaddViewが理由かもしれない同じパラメータtr_head2、とあなたのコードにあるようです。

関連する問題