Good afternoon friends, get to the point:
public class MainActivity extends AppCompatActivity {
Fragment currentFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.mwelcome:
this.currentFragment = new WelcomeFragment();
break;
this.currentFragment = new MapFragment();
case R.id.map:
break;
}
return super.onOptionsItemSelected(item);
}
}
Well I tell you I get an error in the following two lines:
this.currentFragment = new WelcomeFragment();
and also in
this.currentFragment = new MapFragment();
Just in case MapFragment and WelcomeFragment have them there are these codes:
MapFragment:
public class MapFragment extends Fragment {
public MapFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_map, container, false);
}
}
WelcomeFragment:
public class WelcomeFragment extends Fragment {
public WelcomeFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_welcome, container, false);
}
}
Please help me the error that comes to me is:
Incompatible types.
Required:
android.support.v4.app.Fragment
Found:
com.example.david.udemy_09_maps.fragments.MapFragment
Thank you very much friends I hope your help:).