Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are several things wrong with your code:</p> <p>First, the <code>LayoutInflater.inflate()</code> method expects the id of a layout file in the form of <code>R.layout.layout_name</code> and not in the form of <code>R.id.some_id</code>:</p> <pre><code>TextView textView = (TextView) inflater.inflate(R.layout.textView, null); </code></pre> <p>Second, the code you use will throw a <code>ClassCastException</code> because the root of the inflated layout is a <code>LinearLayout</code> and not a <code>TextView</code> as you try to cast it. Your code should be:</p> <p>LinearLayout ll = (Linearlayout) inflater.inflate(R.layout.textView, null);</p> <p>But even the line above will not work because, as its name suggest, a <code>TextSwitcher</code> will take only children of type <code>TextView</code>, nothing can come between the <code>TextSwitcher</code> and the two <code>TextView</code> children. The correct code to use will be in the end:</p> <p>Layout for <strong>textview.xml</strong>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; </code></pre> <p>And the <code>viewFactory</code> field will be:</p> <pre><code>private ViewFactory viewFactory = new ViewFactory() { public View makeView() { LayoutInflater inflater = LayoutInflater.from(TextSwitcherTest.this); TextView textView = (TextView) inflater.inflate(R.layout.textView, null); return textView; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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