Linkify the text if text from string array

Put your problem here if it does not fit any of the other categories.

Linkify the text if text from string array

Postby sarahjosh » Sun Sep 11, 2011 10:52 am

<string-array name="word">
<item>buffer</item>
<item>unique</item>
<item>parent</item>


</string-array>

<string-array name="desc">
<item>This is a <u>unique</u> ...</item>
<item>Its<u>parent</u> user</item>
<item>This memory space used.... </item>
In an activity I have 2 textviews.One for displaying word and second one for description. In the desc textview, how can it linkify the term same as word(for example "unique" in first definition) and onclick of that it should show a page with word "unique" and corresponding description. Can anybody please help how to do this? Thank you..

try{
final Context context = this.getApplicationContext();
CharSequence sequence = Html.fromHtml(context.getString(R.array.word));
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
UnderlineSpan[] underlines = strBuilder.getSpans(0,strBuilder.length(),UnderlineSpan.class);
for(UnderlineSpan span : underlines) {
int start = strBuilder.getSpanStart(span);
int end = strBuilder.getSpanEnd(span);
int flags = strBuilder.getSpanFlags(span);
ClickableSpan myActivityLauncher = new ClickableSpan() {
public void onClick(View view) {
if(view == wordTextview){
wordTextview.setText(view.toString());
}

}
};

strBuilder.setSpan(myActivityLauncher, start, end, flags);
}
}catch(Exception e){

}

descTextview.setMovementMethod(LinkMovementMethod.getInstance());
sarahjosh
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Sep 11, 2011 10:46 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests