• Android基础教程——在TextView中显示Html 自定义标签,获取标签属性


    In my work, I have to add custom links (use custom tag) in each listview item. I met two problems and have searched by Google and stackoverflow, but no result... Here is the code segment and I process the tag with TagHandler.

    TextView tv = (TextView)paramView.findViewById(R.id.tv_dynamics_desc);
    tv.setClickable(true);
    tv.setText(Html.fromHtml("<uc id=\"133\">This is a Uc link</uc>", null, this));
    tv.setMovementMethod(LinkMovementMethod.getInstance()); 

    The  problem is how to get the attribute: id.

    @Override
    public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
        if(tag.toLowerCase().startsWith("uc")) {
            if (opening) {
                //String id = xmlReader.getProperty( "id" ).toString();
      //<=== to get the attribute, but failed with exception of no such property.
                startClick(tag, output, xmlReader);  
            } else {  
                endClick(tag, output, xmlReader);  
            }
        }
    }

    xmlReader.getProperty( "id" ).toString(); does not work here. Is there any way to get the attribute directly? the ansow is "yes". but I don't know now~! I met the same problem and i will save it and record it at here!  

  • 相关阅读:
    顺序查找
    折半查找
    KMP
    php长时间的脚本,报502
    AcWing 27. 数值的整数次方
    acwing 25. 剪绳子
    Best Cow Line <挑战程序设计竞赛> 习题 poj 3617
    acwing 23. 矩阵中的路径
    AcWing 34. 链表中环的入口结点
    AcWing 33. 链表中倒数第k个节点
  • 原文地址:https://www.cnblogs.com/smallerpig/p/3646079.html
Copyright © 2020-2023  润新知