Android, setonclicklistner to dynamically generated array of textviews

后端 未结 2 397
梦如初夏
梦如初夏 2021-01-15 19:11

I have a dynamically generated array of textviews

for(int i = 0; i < blog_link_counter; i++) {
textViewArray[i] = new TextView(this);
textViewArray[i]         


        
2条回答
  •  -上瘾入骨i
    2021-01-15 19:56

    Just call setOnClickListener(OnClickListener) then on each of your TextViews.

    for(int i = 0; i < blog_link_counter; i++) {
        textViewArray[i] = new TextView(this);
        textViewArray[i].setText(Html.fromHtml(array_blog_text[i]+"
    ")); textViewArray[i].setId(i); textViewArray[i].setOnClickListener(listener); ((LinearLayout) linearLayout).addView(textViewArray[i]); }

提交回复
热议问题