I\'m getting an error in this part of code:
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragm
If you are using support library, you should ensure to import both Fragment and FragmentManager from the support library. You will also need to ensure to load the support fragment manager.
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
//other imports here...
public class SomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_some);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
if(fragment == null) {
fragment = new SomeFragment();
fm.beginTransaction().add(R.id.fragment_container, fragment).commit();
}
}
}
use getSupportFragmentManager()
Instead of getFragmentManager()
getSupportFragmentManager()
.beginTransaction()
.replace(in.jama.app.R.id.container, new Fragment())
.commit();
import android.app.Fragment;
works with getFragmentManager()
method but before you have to remove the import android.support.v4.app.Fragment;