我正在创建动态行并在表格布局中添加此行。在创建行的时间,设置每个textView的值。但是我们在每个行项目的点击监听器上设置值时遇到问题。实际上我们在每行内部有两个textView,并且在第一个文本视图的onclick上打开数据选择器。所以我想在textview上这么约会。
tableLayout = (TableLayout) dialog.findViewById(R.id.tableLayout_popup);
View tableRow = LayoutInflater.from(MileStoneActivity.this).inflate(R.layout.cdd_popup1st_row, null, false);
tableLayout.addView(tableRow);
for (int i = 0; i < masterDataList.size(); i++) {
/* if (i == 0) {
View tableRow = LayoutInflater.from(MileStoneActivity.this).inflate(R.layout.cdd_popup1st_row, null, false);
tableLayout.addView(tableRow);
} else {*/
final View tableRow1 = LayoutInflater.from(MileStoneActivity.this).inflate(R.layout.cdd_popup_row, null, false);
tableRow1.setId(i);
tv1 = (TextView)tableRow1.findViewById(R.id.textView24);
tv2 = (TextView)tableRow1.findViewById(R.id.textView25);
tv2.setId(i);
tv1.setText(masterDataList.get(i).getLineItemNumber());
tv2.setText((masterDataList.get(i).getRequestedDeliveryDate()));
tv2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rowNumber = tableRow1.getId();
new DatePickerDialog(MileStoneActivity.this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
// dialog.dismiss();
// }
}
});
tableLayout.addView(tableRow1);
这是我的日期选择列表: myCalendar = Calendar.getInstance();
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
我未能设置tv2的文本值。我想更改已单击的特定行的值。请帮助我。任何帮助都会得到高级的赞赏。
答案 0 :(得分:0)
我知道我是否帮助你,但你可以让日期成为一个返回听众的方法。在该方法中,将tv2作为参数传递,然后使用此参数传递updateLabel。
private DatePickerDialog.OnDateSetListener getDate(final TextView tv){
return new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel(tv);
}
};
}
然后在DatePicker构造函数中执行此操作:
new DatePickerDialog(MileStoneActivity.this, getDate(tv2), myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();