0

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 first 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. So I change the tag to "uc+id", such as uc133, and this solve the problem, although a little ugly.

Is there any way to get the attribute directly?

The second is the listview item can NOT receive the touch event, no matter I touch the links or the other area of the item.

Artem Russakovskii said he also met this problem in a comment here.

I'm from China, so sorry for my poor English.

Thanks very much:)

Community
  • 1
  • 1
理想评论学派
  • 1,001
  • 4
  • 12
  • 21

1 Answers1

1

I got the same problem and I solved the first problem like this:

final String html = "萝卜白菜的博客<img src='http://m3.img.libdd.com/farm3/115/BBE681F0CAFB16C6806E6AEC1E82D673_64_64.jpg'/><mytag id='123' color='blue'>自定义</mytag>";

Using your way, I got nothing:

final String color = (String) xmlReader.getProperty("mytag123");
Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82