Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use android support library correctly
    text
    copied!<p>I'm working my way through Professional Android 4 Application Development. Chapter 4 modifies the To Do List app to use fragments, but I'm trying to test on a Gingerbread device. There's mention in the book of using support libraries to allow using Android v3 or v4 features on a lower version device, but it's not covered very well.</p> <p>I'm running into a problem specifically with:</p> <pre><code> // Get references to the Fragments android.app.FragmentManager fm = getFragmentManager(); ToDoListFragment todoListFragment = (ToDoListFragment) fm.findFragmentById( R.id.ToDoListFragment ); </code></pre> <p>I've got these imports at the top: import android.support.v4.app.FragmentManager; import android.support.v4.app.ListFragment;</p> <p>But lint warns on the "ToDoListFragment todoListFragment = (ToDoListFragment)" line: cannot cast from Fragment to ToDoListFragment</p> <p>In my ToDoListFragment class, I have:</p> <pre><code> import android.support.v4.app.ListFragment; public class ToDoListFragment extends ListFragment { } </code></pre> <p>This is almost verbatim from the book, except for the change to use support library.</p> <p>I'm not clear on how to get this code to work correctly using the v4 support library. I apologize in advance if this isn't enough info. I'm still learning this, and I'm more familiar with C/C++ than Java. If I don't use the support library, the code builds just fine and will run on an Ice Cream Sandwich device, but I'd like to get it working on lower level devices, too.</p>
 

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