0
我已經動態創建表格行並添加了表格佈局 ,現在我想在用戶選擇另一行時更改所選行和參數textview的背景顏色上一行顏色應該禁用。 在此先感謝。下面是 是我的代碼。如何更改背景顏色動態創建的表格行
for(int s=0;s<lstFilteredTradeOrder.size();s++)
{
final TableRow tableRow = new TableRow(OrderbookFragment.this.getActivity());
tableRow.setId(s);
tableRow.setClickable(true);
tableRow.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
tableRow.setWeightSum(1);
final View rowView;
rowView = OrderbookFragment.this.getActivity().getLayoutInflater().inflate(R.layout.custom_order_book, null);
TextView textName = (TextView)rowView.findViewById(R.id.txt_name);
TextView textLastUpdated = (TextView)rowView.findViewById(R.id.txt_lastupdated);
TextView textAction = (TextView)rowView.findViewById(R.id.txt_action);
TextView textOrdPrice = (TextView)rowView.findViewById(R.id.txt_ordprice);
TextView textOrdQty = (TextView)rowView.findViewById(R.id.txt_ordqty);
TextView textStatus = (TextView)rowView.findViewById(R.id.txt_status);
final ImageView imageView =(ImageView)rowView.findViewById(R.id.image_arrow);
textName.setText(lstFilteredTradeOrder.get(s).getstockCodeName());
textLastUpdated.setText(FormatUtil.formatDateString(String.valueOf(lstFilteredTradeOrder.get(s).getLastUpdate()),
"yyyyMMddHHmmss", "dd/MM/yyyy HH:mm:ss"));
textAction.setText(lstFilteredTradeOrder.get(s).getAction());
textOrdPrice.setText(String.format("%.3f", lstFilteredTradeOrder.get(s).getPrice()));
textOrdQty.setText(FormatUtil.formatOpDouble(lstFilteredTradeOrder.get(s).getQuantity()));
textStatus.setText(lstFilteredTradeOrder.get(s).getStatusText());
tableRow.addView(rowView);
tableRow.setOnClickListener(new View.OnClickListener() {
Boolean color=true;
public void onClick(View view) {
// here would like to change the background color.
TradeOrder selectOrd= lstFilteredTradeOrder.get(tableRow.getId());
constructOrderbookOnclick(selectOrd);
}
});
tblOrderbookDetails.addView(tableRow, new TableLayout.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
}
謝謝你,但它無法正常工作,因爲當我選擇另一行前一行還強調,我想在同一時間,突出一行。 –