开发者

Why value of gettag() is coming null on onclicklistener of textview?

outside onclick listener i am getting tags value but inside onclick listener i am getting null value

 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());

Getting this value 04-21 18:13:03.813: INFO/Tag detai(514): tagging some data

   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+">>>>>>>>>>>>>");

Getting this value 04-21 18:13:06.072: INFO/magic(514): <<<<<<<<<<>>>>开发者_JAVA百科>>>>>>>>

}
            catch(Exception exe)
            {
                Toast(exe.getMessage());
                Log.i("error", exe.getMessage());
            }
            }
        });
        tr[0].addView(txt[t]);


Try

String str=(String) v.getTag();


You need to access the tag like this

txt[0].setOnClickListener(new View.OnClickListener() 
{
    public void onClick(View v) 
    {
        try
    {
    String tag=(String) v.getTag(); 
}
        catch(Exception exe)
        {
            Toast(exe.getMessage());
            Log.i("error", exe.getMessage());
        }
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜