在 onclick 监听器外部我得到标签值但在 onclick 监听器内部我得到空值
TableRow[] tr= new TableRow[1];
final TextView[] txt= new TextView[1];
tr[0] = (TableRow) new TableRow(this);
txt[0]=new TextView(this);
txt[0].setWidth(intcolumnwidth1);
txt[0].setText("txt7");
txt[0].setBackgroundResource(R.layout.shape2);
txt[0].setTextColor(intwhite);
txt[0].setTag("tagging some data");
Log.i("Tag detail", (String) txt[0].getTag());
获取此值 04-21 18:13:03.813: INFO/Tag detai(514): 标记一些数据
txt[0].setClickable(true);
txt[0].setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try
{
String str=(String) txt[t].getTag();
Log.i("magic","<<<<<<<<<<<"+str+">>>>>>>>>>>>>");
获取此值 04-21 18:13:06.072: INFO/magic(514): <<<<<<<<<<>>>>>>>>>>>
}
catch(Exception exe)
{
Toast(exe.getMessage());
Log.i("error", exe.getMessage());
}
}
});
tr[0].addView(txt[t]);
最佳答案
尝试
String str=(String) v.getTag();
关于android - 为什么 gettag() 的值在 textview 的 onclicklistener 上变为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5744495/