如何获得的TextView的包含在OnClickListener线性布局的名字吗? [英] How to get the name of textview included in linear layout in OnClickListener?

查看:210
本文介绍了如何获得的TextView的包含在OnClickListener线性布局的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态地添加textviews线性布局,并希望得到TextView的线性layout.This的OnClickListener点击的名称是code:

I am adding textviews dynamically to a linear layout and want to get the name of the textview clicked in OnClickListener of linear layout.This is the code:

m_lvSideIndex = (LinearLayout)ShowTheContacts1.this.findViewById(R.id.sideIndex);
TextView l_tempText = null;

for(int l_a = 0;l_a < m_arrayOfAlphabets.length;l_a++)
{
    l_tempText = new TextView(ShowTheContacts1.this);
    l_tempText.setGravity(Gravity.CENTER);
    l_tempText.setTextSize(15);
    l_tempText.setTextColor(getResources().getColor(R.color.black));
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1);
    l_tempText.setLayoutParams(params);;
    l_tempText.setText(m_arrayOfAlphabets[l_a]);
    m_lvSideIndex.addView(l_tempText);
    m_lvSideIndex.setTag(l_a);
}

m_lvSideIndex.setOnClickListener(new OnClickListener() 
{               
    @Override
    public void onClick(View v) 
    {
        String l_itemSelected = (String)v.toString();  //Want to get the name of textview selected here
});

请帮忙me.Thanks提前。

Please help me.Thanks in advance.

推荐答案

您可以用它做getTag的帮助()

You can do with it the help of getTag()

第一setTag()值即TextName

first setTag() the value i.e TextName

m_lvSideIndex.setTag(m_arrayOfAlphabets[l_a]);
m_lvSideIndex.setTag(l_a, R.id.sideIndex);

和通过getTag获得价值()

and get the value via getTag()

m_lvSideIndex.setOnClickListener(new OnClickListener() 
{               
    @Override
    public void onClick(View v) 
    {
        String l_itemSelected = (String)v.getTag(); 
        Integer l_position = (Integer)v.getTag(R.id.sideIndex);   
});

这篇关于如何获得的TextView的包含在OnClickListener线性布局的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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