如何在android中动态设置表格布局中的行项目值?

如何在android中动态设置表格布局中的行项目值?,android,tablelayout,tablerow,Android,Tablelayout,Tablerow,我正在创建动态行,并将该行添加到表布局中。在创建行期间,将设置每个textView的值。但我们在设置每行项目的click listener的值时遇到问题。实际上,每行中有两个textView,单击第一个文本视图时,我们打开数据选择器。所以我想在textview中设置日期值 tableLayout = (TableLayout) dialog.findViewById(R.id.tableLayout_popup); View tableRow = LayoutInflater.from(Mil

我正在创建动态行,并将该行添加到表布局中。在创建行期间,将设置每个textView的值。但我们在设置每行项目的click listener的值时遇到问题。实际上,每行中有两个textView,单击第一个文本视图时,我们打开数据选择器。所以我想在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);

我未能设置tv2的文本值。我想更改已单击的特定行的值。请帮帮我。如有任何帮助,我们将不胜感激

我不知道我是否理解正确,但你可以将date作为一种返回侦听器的方法。在方法中,将tv2作为参数传递,然后使用此参数更新标签

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

我不知道我是否理解正确,但你可以将date作为一种返回侦听器的方法。在方法中,将tv2作为参数传递,然后使用此参数更新标签

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

谢谢你的回复。但是我怎么知道tv2 textView属于哪一行呢to@Anand通过电视,您可以获得parentView,这将是行。它将设置最后一行textview的值,而不是所需的行。请告诉我任何其他设置值的方法。。我不想。。你的答复花了很长时间。但是我怎么知道tv2 textView属于哪一行呢to@Anand通过电视,您可以获得parentView,这将是行。它将设置最后一行textview的值,而不是所需的行。请告诉我任何其他设置值的方法。。我不想。。花了很长时间