[英]How to set value of row item in Table Layout dynamically in android?
我正在創建動態行並在表格布局中添加此行。在創建行的時間,設置每個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的文本值。 我想更改已單擊的特定行的值。 請幫助我。 任何幫助都會得到高級的贊賞。
我知道我是否幫助你,但是你可以讓日期成為一個讓聽眾回歸的方法。 在該方法中,將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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.