我正在将文本视图动态添加到线性布局中,并希望获取在线性布局的 OnClickListener 中单击的文本视图的名称。这是代码:
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
});
请帮助我。在此先感谢。