-2

I am passing the string via an ArrayList Hashmap. My code is as follows;

        Adapter1 = new SimpleAdapter(getBaseContext(), myList,
                R.layout.content, new String[]{ "TA", "IA"},
                new int[]{R.id.ta, R.id.ia});
        listview.setVerticalScrollBarEnabled(true);
        listview.setAdapter(Adapter1);

What gets passed is really the values of "TA" and "IA" keys of the Hashmap. They go straight to TextViews at R.id.ta, R.id.ia.

How do I bold only a section of that text. For example, it contains a number, and I want to bold only that number. (I don't want to bold R.id.ta, R.id.ia fully)

Please help. Thanks!

Zac
  • 695
  • 1
  • 11
  • 34
  • 1
    Possible duplicate of [Making part of a string bold in textview](https://stackoverflow.com/questions/20850822/making-part-of-a-string-bold-in-textview) – AskNilesh Dec 22 '17 at 04:41
  • I can't use StyleSpan like it's mentioned in the link because my values are in an ArrayList Hashmap which get set via a SimpleAdapter. Did you read the question? – Zac Dec 22 '17 at 05:13
  • you need to get number from your string and make that number bold using Spannable string – AskNilesh Dec 22 '17 at 05:18
  • First, I don't know how to get the string to a new string. That is the crux of this question. Then I can think of editing the string. – Zac Dec 22 '17 at 07:23
  • get the number from string like this https://stackoverflow.com/questions/26306135/how-to-read-characters-in-a-string-in-java – AskNilesh Dec 22 '17 at 07:27
  • Since there are other suggestions on how to achieve what you want if you can get the String, I think your question should be more focused on getting the exact String from key values somehow.. Consider editing your post. – Taslim Oseni Dec 22 '17 at 08:24

2 Answers2

0

Try this

String sourceString = "<b>" + boldText + "</b> " + normalText;
mytextview.setText(Html.fromHtml(sourceString));
Rahul Singh Chandrabhan
  • 2,531
  • 5
  • 22
  • 33
-1

I see you are using custom layout. Then you can do something like below

There are two methods to make some text bold

  1. HTML text
  2. SpannableStringBuilder

A useful post for this can be found at this SO post. If you want to highlight/bold only number then this can be acheived using Regex. Useful example for the same SO post

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60
  • I can't use these because my values are in an ArrayList Hashmap which get set via a SimpleAdapter. – Zac Dec 22 '17 at 05:14
  • Have you checked the 2nd option i.e. SpannableStringBuilder. It will give you the string after all which you can pass in your string array. **SpannableStringBuilder str = new SpannableStringBuilder("Your awesome text"); str.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), INT_START, INT_END, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);** – Rahul Khurana Dec 22 '17 at 05:17
  • First, I don't know how to get the string to a new string. That is the crux of this question. Then I can think of editing the string. – Zac Dec 22 '17 at 07:24
  • if you don't know how to implement the same , then why you downvote my answer?? – Rahul Khurana Dec 22 '17 at 08:25