Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue in adding images dynamically to TextView
    primarykey
    data
    text
    <p>Below is my <code>Activity</code> <code>Layout</code> XML</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:bufferType="spannable" android:id="@+id/textView" android:text="@string/empty" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>and this below is the code which I use within my <code>Activity</code></p> <pre><code> TextView tView = (TextView) findViewById(R.id.textView); for(int i=0;i&lt;15;i++){ appendDrawable(tView,R.drawable.ic_launcher); appendText(tView,R.string.message); } </code></pre> <p>and the methods are :</p> <pre><code>private void appendDrawable(TextView tView, int drawableId) { SpannableStringBuilder builder = new SpannableStringBuilder(); String THREE_SPACES = " "; builder.append(THREE_SPACES); Drawable drawable = getResources().getDrawable(drawableId); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan image = new ImageSpan(drawable); builder.setSpan(image, 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tView.append(builder); } private void appendText(TextView tView, int stringId) { tView.append(getResources().getString(stringId)); } </code></pre> <p>and the output which I got is not what I expected 3 missing <img src="https://i.stack.imgur.com/sMdp7.jpg" alt="output from Nexus"></p> <p>and if I tilt the screen 1 missing <img src="https://i.stack.imgur.com/QJUrN.jpg" alt="output from Nexus"></p> <p>Can anyone help me in finding out why the images went missing and if there is a better way of doing this.</p> <p>Expected Output : As per the loop it should display (drawable, Hello World)15 times but in this example the drawable wasn't rendered thrice(and once when I tilted). Some issues with wrapping?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload