Java Android: Make a word (from a paragraph) into a button - java

I searched for some answers, but came up empty, maybe I'm not wording my question correctly.
Basically I want a hyper link, except it has a java on click listener attached to it, instead of an html link. I have some paragraphs of text and certain words are highlighted, I want the user to be able to click those words and it executes a function.
Any thoughts or website tutorials? Thanks.

You should use the Linkify class to achieve what you want. Here is a full tutorial that will help you

Related

POP up appears without clicking the Link

I'm automating this site:
When I click a button a pop up is displayed. There is a link on the screen to display the pop-up but I don't have anything in my code to click the link this code is commented out.
//Please click to confirm you read and accept the conditions
driver.findElement(By.id("assumptionsConfirmed1")).click();
Please try with xpath i think this might work for you bcz i have seen in resources and xpath look more better than id.
driver.findElement(By.xpath("//a[contains(text(),'assumptions and terms and conditions before procee')]")).click();

Intellij: How to find a method?

I need to find what method was called when I tap on something. The project is huge and find it by myself will take a good amount of time.
Is there any possible way to do that?
I'm using Android Studio and yeah I'm working with another person's project for the first time ever.
How I do this:
Let's say that the button has some text. Let's say, it is Login.
Go to the strings.xml, and find the text, matching the text on the button.
use Find Usages in Android Studio on the found string.
In layout XML file observe the button, which text is set to the Login string.
Use Find Usages on the ID of the button
Open the Java file, where the ID of the button is used (usually it is used in findViewById())
use Find Usages on the Button object which is found by id.
Find the setOnClickListener of that button.
see, what is called in that listener.
I'm not sure whether this somehow answers your questions, but at least I found "Analyzing Data Flow" very helpful in messed up projects.
Here's a nice article concerning the feature by Sebastiano Poggi.
Also a gif demostrating the feature in action:
It's also accessible through context menu:

Java Pseudo-Hyperlink

So I am working on something in Java right now where I need to display lots of JTextComponents. I need to be able to turn words in any text component into a hyperlink of sorts, specifically, when these words are clicked, some method is called. Please note, I am not looking for a REAL hyperlink, just if you click on some text, a function is called. I believe JTextPane could solve this problem using components, but I can't seem to figure it out..
Yes, this question already exists, but the other one is a duplicate, and the one it links to does NOT answer this question.
If JEditorPane or JTextPane is a satisfactory JTextComponent, then a HyperlinkListener will be invoked to perform any desired action, as shown in this complete example.
A JTextArea could work for this too.
You could use a MouseListener and then translate the location of the click via viewToModel(Point pt).
You could then use javax.swing.text.Utilities.getRowStart(textArea, offset); if you need the start of the row selected, and getRowEnd(...) for the end.
You could have a Map<String, SomeLink> to see if a selected word is a linking word.
For an example of this, please check my answer here.

Converting BB code to HTML for TextView

I'm trying to convert BB code to HTML in Java for an Android project. An example of the text in which the bb code is embedded looks like this:
[b]This[/b] is some [url="http://www.example.com"]example[/url] text
to display my problem.
There also might be several paragraphs [i]of[/i] text and normal URLs http://www.example.com.
What it needs to look like in the TextView:
This is some example text to display my problem.
There also might be several paragraphs of text and normal URLs http://www.example.com.
Unfortunatly I don't have any code to show you since i don't know how to go about doing this. The only thing i can come up with now is making alot of regular expressions but i´m not sure if that would be the best solution.
Eventually this will all be displayed in an Android TextView.
Any help is appreciated!
There are some java BB-code libraries out there. Check this question for information on them.

How to set webview area upon loading a link?

Ok so I have an rss reader that links to articles. One of the sites it links to doesn't have a mobile view. I was wondering if anyone knew if it was possible to set the "zoom" and position of the view once the page is loaded? So for instance if the following link were my article... http://www.neworleanssaints.com/news-and-events/article-1/Saints-agree-to-terms-with-7th-round-pick-Sean-Canfield/cce6a9ca-eaee-4878-ad40-0b98609f7fe7
Then how could I have the view focus on the article without the user having to zoom in and scroll the the top of the article. Thanks.
I think, you have to use an anchor, which are based on the ids of the HTML code. Then, you have to pass the Id you want to stick to after the url and a #.
With your example, it would give something like that :
http://www.neworleanssaints.com/news-and-events/article-1/Saints-agree-to-terms-with-7th-round-pick-Sean-Canfield/cce6a9ca-eaee-4878-ad40-0b98609f7fe7#c1256209263986
As the div you are looking for has an id (lucky you cause they don't have all the time)
<div id="c1256209263986" class="iw_component"><div xmlns:esi="http://www.edge-delivery.org
Hope this will help you (Try to click on the link I put, this should open the page at the start of the article.)
I never tried that but have a go a this, and come back to tell me if it worked.

Categories