Using Linkify in ListView's ArrayAdapter causes RuntimeException

前端 未结 3 1394
说谎
说谎 2021-01-16 09:18

I have a TextView in my ArrayAdapter that may contain some hyperlinks. For those links I use Linkify:

public View get         


        
3条回答
  •  既然无缘
    2021-01-16 09:46

    In your Activity.Java while binding your list with adapter

    YourAdapter yourAdapter = new YourAdapter(YourCurrentActivityName.this, YourArrayList);
    yourListView.setAdapter(yourAdapter); 
    

    In YourAdapter.java in Constructor make sure it's Activity not Context

    public YourAdapter(Activity context, YourArrayList list){
        this.context = context;
        this.list = list;
    }
    

    And, use this code for your textview in your adapter for Linkify.

    holder.yourTextView.setLinksClickable(true);
    holder.yourTextView.setMovementMethod(LinkMovementMethod.getInstance());
    Linkify.addLinks(holder.yourTextView, Linkify.ALL);
    holder.yourTextView.setAutoLinkMask(Linkify.ALL);
    

提交回复
热议问题