我创建了一个表行,如果我点击网格项它显示这个表行,我需要这个表行Scrollable,我想在表格布局中添加动态滚动视图,但它崩溃当我使用onclick,任何人都可以帮我这个,因为我还需要添加相同类型的项目它会增加数量列中的nuber例如:如果我点击蛋卷2次它将添加数量列2没有在图片中添加另一行,总价格也相同Here's the example抱歉我的英文不好
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();
}
});