How to make each word text clickable?

Guys, this is a sample text: "I want this [option1 / option2] to be clickable."

What should I do when the user clicks an option (or a word), I will save the pressed word in a variable. How to make these options available?

Thanks for any help ..

+4
source share
2 answers

This is a blog with the example you need. It helped me a lot. Blog Link

Code from the blog how you can do this.

In your main task "Links". In this way.

mTextSample = (TextView) findViewById(R.id.text1); text = "<html>Visit my blog <a href=\"http://sherifandroid.blogspot.com\">mysite</a> or run the <a href=\"sherif-activity://myactivity?author=sherif&nick=king\">myactivity</a> callback</html>"; mTextSample.setText(Html.fromHtml(text)); mTextSample.setMovementMethod(LinkMovementMethod.getInstance()); 

To get the parameters:

 TextView mTextSample = (TextView) findViewById(R.id.text); mTextSample.setText(getIntent().getData().getQueryParameter("author")); mTextSample = (TextView) findViewById(R.id.text1); mTextSample.setText(getIntent().getData().getQueryParameter("nick")); 

In the manifest, declare the second action as:

 <activity android:label="@string/app_name" android:name="sherif.android.linkify.example.TestActivity"> <intent-filter> <data android:scheme="sherif-activity" android:host="myactivity"/> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> </intent-filter> </activity> 
+3
source

cannot do this easily without checking inside the text view in the onTouch event which part of the text message has touched (includes checking x, y of the touch position inside the text field)

to do what you want to do, easily use 2 text fields and set 2 different onClickListener

check this out for more details http://developer.android.com/guide/topics/ui/ui-events.html on how to set clickers

-1
source

Source: https://habr.com/ru/post/1380558/


All Articles