Nitin Makwana Nitin Makwana - 4 months ago 11
Android Question

When i Add Fragments Dynamically it showing error

Whenever i add fragments dynamically it showing error in Main Activity it does not resolve FragmentManger class.

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

FragmentManager fragmentManager=getFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
FirstFragment ff= new FirstFragment();
fragmentTransaction.add(R.id.fragment_container,ff);
fragmentTransaction.commit();
}


thanks For help in Advance..

Cgx Cgx
Answer
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(R.id.container, MyFragment);  
    transaction.show(mapFragment);
    transaction.commit();