@Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new HomeFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new FriendsFragment();
title = getString(R.string.title_friends);
break;
case 2:
fragment = new MessageFragment();
title = getString(R.string.title_messages);
break;
default:
break;
}
the error printed is:
incompatible types,required android.app.fragment but found activity.messagefragment
In your messagefragment
class you need to import
import android.app.Fragment;
Instead of
import android.support.v4.app.Fragment;
You have probably included the wrong class, check your import statements.
You should have this in there:
import android.app.Fragment;
Your Activity
must extend from AppCompatActivity
, then you call your fragment using getSupportFragmentManager
, that should do it.
It'll go like this:
getSupportFragmentManager().beginTransaction().replace(R.id.main_container, TabFragment.newInstance()).commit();
Check imports of all the fragment java classes and make sure that they all have
import android.app.Fragment;
Instead of
import android.support.v4.app.Fragment;
It solves.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With