24638

add ListFragment with FragmentTransaction is not supported?

I have a ListFragment:

public class MyListFragment extends ListFragment{ ... }

In order to use <strong>Fragment</strong> in my <strong>Android 2.1 API 7</strong> project, I use the support package. (Everything has configured for the support package)

In my host <strong>Activity</strong> looks like:

import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; public class FragmentNavActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... FragmentManager fMgr = getSupportFragmentManager(); FragmentTransaction fTrans = fMgr.beginTransaction(); MyListFragment myListFragment = new MyListFragment(); fTrans.add(android.R.id.content, myListFragment).commit(); //problem here ... } }

The problem is that the FragmentTransaction 's .add(int, Fragment) method accept arguments with the second one of type Fragment, however, I have ListFragment which is not acceptable by this method.

So, how to add ListFragment with FragmentTransaction ?

Answer1:

Maybe the problem is because you are importing android.support.app.ListFragment

Answer2:

Try using nested fragments. In that way you can wrap your ListFragment inside a Fragment, which you can use in your FragmentTransaction

Nested Fragments

Recommend

  • How to send an std::vector of unsigned char over an UDP socket using boost asio?
  • ActionBar with appcompat library v7 (ava.lang.IllegalStateException: You need to use a Theme.AppComp
  • Android TabLayout on the bottom of the screen
  • Android NFC read Tags issue. Activity starts each time on data received
  • openssl handshake failed
  • How to resolve docker host names (/etc/hosts) in containers
  • Cordova Apache wrong module path
  • How do you keep a running instance for Google App Engine
  • ASPNetCore MVC Routing Let Server Handle Specific Route
  • EditText is covered by Keyboard
  • Prevent Tomcat from caching request during starup
  • URLConnection doesn't work since API 10 and higher?
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Unity3D & Android: Difference between “UnityMain” and “main” threads?
  • Disable Enter in editText android
  • Cannot resolve symbol 'MyApi'
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • JFileChooser in front of fullscreen Swing application
  • req.body is undefined - nodejs
  • HTML download movie download link
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • sending/ receiving email in Java
  • Symfony2: How to get request parameter
  • Eraser for UIBezierPath
  • Release, debug version and Authorization Google?
  • Why winpcap requires both .lib and .dll to run?
  • Akka Routing: Reply's send to router ends up as dead letters
  • Return words with double consecutive letters
  • Is there a mandatory requirement to switch app.yaml?
  • Python: how to group similar lists together in a list of lists?
  • Suggestions to manage Login/Logout transitions
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • need help with bizarre java.net.HttpURLConnection behavior
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Busy indicator not showing up in wpf window [duplicate]
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?