question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handling Link Event in TextView

See original GitHub issue

Hi @noties, I am new to this library and I am stuck with handling the links on my TextView. On click I am getting the following message: W/LinkResolverDef: Actvity was not found for intent, Intent { act=android.intent.action.VIEW dat=Romans:1:18 (has extras) } I need to pick the text Romans1:18 from the link and format it for further processing. Can you please guide me to use this library?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
notiescommented, Apr 19, 2018

Hey @sandeepyohans !

There are multiple way to do so, the most simple would be:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getContext())
            .setTitle("My title")
            .setMessage(Markwon.markdown(getContext(), "**M**arkdown here"))
            .setPositiveButton(android.R.string.ok, null)
            .create();
}

You can use, but only if you absolutely sure that your markdown doesn’t contain tables or images. If you need to support tables and images you can do this:

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // please note that it is only an example, as you should create a correctly
    // styled TextView most likely with a help from LayoutInflater and a layout file
    final TextView textView = new TextView(getContext());
    Markwon.setMarkdown(textView, "**M**arkdown here");

    return new AlertDialog.Builder(getContext())
            .setTitle("My title")
            .setView(textView)
            .setPositiveButton(android.R.string.ok, null)
            .create();
}

I hope this helps!

3reactions
notiescommented, Apr 10, 2018

Hello @sandeepyohans !

Something like this should do:

final SpannableConfiguration configuration = SpannableConfiguration.builder(this)
        .linkResolver(new LinkSpan.Resolver() {
            @Override
            public void resolve(View view, @NonNull String link) {

                // process clicked link here, match you custom scheme, launch Activity,
                // or really whatever.

                // just for example:
                if ("Romans:1:18".equals(link)) {
                    showFragment(TheBookFragment.newInstance("Romans", 1, 18));
                }
                
                // if for example you still want to redirect _native_ link handling
                // you can check `LinkResolverDef` (or instantiate it here and call manually)
            }
        })
        .build();

Markwon.setMarkdown(textView, configuration, "# My markdown");

Hope this helps! Please keep me updated if it doesn’t answer your needs, we will work something out 🙌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android TextView with Clickable Links: how to capture clicks?
I have implemented a small class with the help of which you can handle long clicks on TextView itself and Taps on the...
Read more >
A better way to handle links in TextView | by Saket Narayan
A better way to handle links in TextView. There are two ways of “linkifying” URLs in a TextView. First, as an XML attribute:...
Read more >
A better way to handle links in TextView - Saket Narayan
A better way to handle links in TextView ... and second, programmatically: TextView textView = (TextView) findViewById(R.id.text1); Linkify.
Read more >
Input events overview - Android Developers
An event listener is an interface in the View class that contains a single callback method. These methods will be called by the...
Read more >
How to Create a Hyperlink Using Android TextView
To create a clickable hyperlink in your Android app using the TextView widget follow ... How to Create a Clickable Link to Another...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found