Android的,setonclicklistner动态生成的textviews阵列 [英] Android, setonclicklistner to dynamically generated array of textviews

查看:190
本文介绍了Android的,setonclicklistner动态生成的textviews阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有textviews
动态生成的阵列

I have a dynamically generated array of textviews

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

现在我有一个活动,其中有许多textviews的。我需要的onclick听者功能添加到所有的textviews的。

Now i have an Activity, where there are a number of textviews. I need to add the onclick listner functionalities to all of the textviews.

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:id="@+id/info"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFFFFF" />

我还说,我实现了onclicklistner接口onclicklistner在java file.After     

I added the onclicklistner in the java file.After that i implemented the onclicklistner interface


    public void onClick(View v) {
        // TODO Auto-generated method stub
    switch(v.getId())
    {
    case R.id.    <--  ?
    }

}}

如何搭配哪个TextView的ID它已经指的是?

How can i match as to which Textview id it's been refering to?

请帮助。

推荐答案

还是叫<一href="http://developer.android.com/reference/android/view/View.html#setOnClickListener%28android.view.View.OnClickListener%29"相对=nofollow> setOnClickListener(OnClickListener) 然后在你的每一个的TextView 秒。

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

这篇关于Android的,setonclicklistner动态生成的textviews阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆