Android:如何通过TAG获取视图?

时间:2016-08-24 14:06:20

标签: android layout tags views identifier

我已经使用标记标识符动态创建了许多按钮,但我不知道如何通过标记找到它们,我已经尝试过 findViewWithTag 但它没有&#39工作。 如果有人可以通过标识符或标签告诉我如何做到这一点? 有人可以帮助我,并举例说明如何做到这一点?

提前谢谢。

这是我的源代码:

 public void onClick(View v) {



    if (v == buttonPlanificationRdvMed) {
    for (int i = 0; i < nbH; i++) {

                    TableRow tr = new TableRow(this);
                    tr.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
                    //tr.setOrientation(tr.HORIZONTAL);
                    TextView text_view = new TextView(this);
                    Button b =  new Button(this);

                    text_view.setWidth(1000);// give how much you need
                    j = j + averageConsultationTime;
                    HMA = ((BeganConsultationH * 60) + (BeganConsultationM))
                            + j - averageConsultationTime;

                    int h = HMA / 60;
                    int m = HMA % 60;
                    b.setBackgroundColor(0xff99cc00);
                    b.setText(h + "H" + nbH);
                    tr.addView(b);

                    for (int k = 0; k < 7; k++) {
                        Button but = new Button(this);
                        but.setTag(table[k]+"_"+h + "H" + nbH);
                        but.setText(but.getTag()+""+table[k]);



                        tr.addView(but);

                    }
                    TL.addView(tr);

                } 

0 个答案:

没有答案