title: Android tumbles custom TextViews onResume
body: <h2>Background</h2>
  
  <p>I have an App with multiple custom TextViews in it.
  These four Custom TextViews are all set up like this:</p>
  
  <pre><code>public class TextView_Light extends android.support.v7.widget.AppCompatTextView {
  
  public TextView_Light(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
      init();
  }
  
  public TextView_Light(Context context, AttributeSet attrs) {
      super(context, attrs);
      init();
  }
  
  public TextView_Light(Context context) {
      super(context);
      init();
  }
  
  public void init() {
      Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Light.ttf");
      setTypeface(tf ,1);
  }}
  </code></pre>
  
  <p>I do have <code>TextView_Bold</code>, <code>TextView_Light</code>, <code>TextView_Regular</code> and <code>TextView_Thin</code>. Each of them uses another font which is saved in <code>assets/fonts</code></p>
  
  <p>I use the TextViews like that:</p>
  
  <pre><code>&lt;de.mayr.wap.app.helper.TextView_Light
              android:id="@+id/textView_Light7"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginStart="8dp"
              android:layout_marginTop="8dp"
              android:text="@string/overviewViaBarcode"
              android:textSize="16sp"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"/&gt;
  </code></pre>
  
  <p>When the App is started and a view shows up for the first time everything looks great, like that:
  <a href="https://i.stack.imgur.com/lW9sB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lW9sB.png" alt="Fine looking view"></a></p>
  
  <hr>
  
  <h2>The Problem</h2>
  
  <p>In this view the user klicks on one of the tablerows, an <code>Dialog</code> appears where the user types in some data. On save the <code>onResume</code> method of the view is called, which calls an Webservice etc. like that:</p>
  
  <pre><code>@Override
  public void onResume() {
      super.onResume();
      callSerNrWS();
  }
  
  
  public void callSerNrWS() {
      if (CheckNetwork.isNetworkAvailable(getContext())) {
          final AsyncResponseFortschritt&lt;ResponseObject&lt;PruefauftraegeVO&gt;&gt; response = new AsyncResponseFortschritt&lt;ResponseObject&lt;PruefauftraegeVO&gt;&gt;() {
              @Override
              public void processFinishSerNr(ResponseObject&lt;PruefauftraegeVO&gt; output) {
                  anw = createPruefAnwArraylist();
                  seriennummerVO = findDataToSerNr();
                  adapt = new PruefAnwAdapter(getContext(), anw, seriennummerVO);
                  pruefListView.setAdapter(adapt);
                  setVisibilityLoadAnimation(View.GONE);
                  if (output.getException() != null &amp;&amp; !output.getException().isEmpty())
                      AlertCreator.makeFailAlert(R.string.titelKeinFortschritt, R.string.textKeinFortschritt,getContext());
              }
              @Override
              public void processStartSerNr() {
                  setVisibilityLoadAnimation(View.VISIBLE);
              }
          };
          AsyncCallSerNrWS ws = new AsyncCallSerNrWS(response, pruefauftraegeVO);
          ws.execute();
      }
  }
  </code></pre>
  
  <p>And after that, theres in 90% of cases one or more <code>TextView</code> which changed its <strong>looking</strong> from eg. <code>TextView_Light</code> to <code>TextView_Thin</code>. Like in the following picture: The appearence of the 'Anzugstrom [A]' in the third row now looks like a <code>TextView_Thin</code> and the '9/48' in the fifth row looks like a <code>TextView_Light</code>
  <a href="https://i.stack.imgur.com/Rkm7u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rkm7u.png" alt="Bad looking view"></a></p>
  
  <hr>
  
  <h2>What I know</h2>
  
  <ul>
  <li>This doesnt happen when the view is shown for the first time</li>
  <li>There isn't any system behind it. It's totally random.</li>
  <li>It happens in activitys and fragments</li>
  <li>It happens in every view i have whatever the TextView contains 'hard-coded' text or text that comes from an Webservice</li>
  <li>Its not just in lists, also in 'normal' views</li>
  </ul>