Java Android - Casting Parent to Child to Child
<p><strong>Update:</strong>
I was being stupid thinking its different in this case. You can't cast a Parent to a Child full stop ;)</p>

<hr>

<p>I'm going mad.</p>

<p>I have a class:</p>

<pre><code>public class ActivityMonitorItemView Extends LinearLayout
</code></pre>

<p>Now I'm using a LayoutInflator to return a LinearLayout. But as this returns a View I'm first casting to a LinearLayout like so:</p>

<pre><code>LinearLayout sillyLayout = (LinearLayout) vi.inflate(R.layout.activity_monitor_item, null);
</code></pre>

<p>But now when I try cast sillyLayout to ActivityMonitorItemView..</p>

<pre><code>ActivityMonitorItemView amtv = (ActivityMonitorItemView) sillyLayout;
</code></pre>

<p>I get a ClassCastException...</p>

<p>Any Ideas? (Actual code used below)</p>

<pre><code>@Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ActivityMonitorItemView v = (ActivityMonitorItemView) convertView;
        if(v == null)
        {
            LayoutInflater vi = (LayoutInflater)OurViewManager.getAnswersRef().getCurrentActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            LinearLayout t = (LinearLayout) vi.inflate(R.layout.activity_monitor_item, null);

            v = (ActivityMonitorItemView) t;
            v.LinkUpToTask(listItems.get(position));
        }


        return v;
    }
</code></pre>
