0

Im new to android and im stuck on implementing a string which contains either a vector or image in a single string or concatenated string. ive tried programatically as well as string resource but nothing came up as expected. I want the result just as an empty view list that is in whatsapp.

Same as this on whatsapp

here is my code for string value...

<string name="empty_Employee">Nothing To Display!!! \n Add
     Data By Tapping The Button At The Bottom Of Your Screen</string>

here is the code for java

TextView tv = view.findViewById(R.id.empty);

    Drawable d = getResources().getDrawable(R.drawable.ic_group_black_24dp);

    tv.setText("Tap "+d+" To add data!");

the above steps do not work..they return string address of the specified drawable

if the question is already answered please link the answer here!!

so can anyone help me!!.. Thx in advance!!

  • Take a look at this https://stackoverflow.com/questions/3176033/spannablestring-with-image-example?answertab=votes#tab-top – Farshad Nov 10 '17 at 10:29

1 Answers1

1

The thing you need is called SpannableString It also allows you to add specific style for different spans of text. This is the way to use it.

SpannableString string = new SpannableString("abc"); 
Drawable d = getResources().getDrawable(R.drawable.ic_group_black_24dp); 
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); 
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); 
string .setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 
textView.setText(string ); 
loshkin
  • 1,600
  • 2
  • 21
  • 38