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