My main activity extends AppCompatActivity where I create and inflate my menu. I also want my main activity to contain a map fragment. This requires that my main activity extends FragmentActivity, but I cannot extend from two super classes. How am I supposed to add a map fragment to my main activity?
AppCompatActivity extends FragmentActivity, so you get all of the functionality in FragmentActivity by extending AppCompatActivity.
Well, AppCompatActivity already extends FragmentActivity, so there should be no problem.
Related
I have a BottomnavigationView in an AppCompatActivity that navigates between Fragments. For one of the Fragments, it's a MasterDetailFragment where you can search in that fragment and it will filter the data in the MasterFragment and you can click on the list to view the DetailFragment (all of this happens while the user is on one of the tabs in BottomNavigationView). I'm trying to use the new arch ViewModel to share the data between Master and Detail fragments: https://medium.com/#bharathkumarbachina/sharing-data-between-fragments-34afb6553380. It says to use getActivity() and share the viewmodel that way, but getActivity() is not getting the AppCompatActivity but instead is getting a FragmentActivity. Do I need to make a new MasterDetailFragmentActivity?
AppCompatActivity is a subclass of FragmentActivity. You can cast the FragmentActivity to AppCompatActivity after doing "instance of" check.
https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html
Toolbar mainly should used with ActionBarActivity
if I want to use it by Extends Activity it gives an error
when I call
setSupportActionBar(toolbar);
I main Above I don,t want to use ActionBarActivity
Any help here , And what About Another kind Of Activities
Like FragmentActivity or Others .
Example to support FragmentActivity
ActionBarActivity activity = (ActionBarActivity) getActivity();
activity.setSupportActionBar(toolbar);
If you're extending Activity just use setActionBar(). setSupportActionBar is for when your're using ActionBarActivity from the support library
You have done little mistake .. you had to extend
ActionBarActivity
not only
Activity
class ..when you do error will be removed.
In the documentar from SlidingMenu is written down:
Go into the SlidingActivities that you plan on using make them extend Sherlock__Activity instead of __Activity.
The setup should be ok, I followed the guide, but if I try to extend my Activity with for example: SlidingSherlockFragmentActivity or SherlockSlidingFragmentActivity doesn't work.
If I extend my Activity with SherlockFragmentActivity I can't get the SlidingMenu with getSlidingMenu() or call setBehindContentView.
Nevermind, go into the SlidingMenu library and extend the Activity by SherlockFragmentActivity instead of FragmentActivity
Go to activities of library SlidingMenu and extends all activities to SherlockActivities corresponding, after go to your app and extends all activities to SlidingActivity corresponding.
Example: SlidingMenu:
SlidingActivity extends SherlockActivity
SlidingMapActivity extends SherlockMapActivity
Example: MyClass
MyClass extends SlidingActivity
MyClass extends SlidingMapActivity
I'm new in Android.
How am I be able to extend an Activity with both MapActivity and ActivityGroup??
Because I need to display both a Map and a customized Tab on an Activty.
public class MainActivity extends ActivityGroup implements MapActivity
Somehow I'm not allowed to do that.
To display a tab use Fragment, coz ActivityGroup is Depreciated.
I have a FragmentActivity:
public class parking extends FragmentActivity { }
It has 3 tabs, the second and third are lists, solved.
public class tab2 extends Fragment{ }
But the first one is a map, so, I can't extend Fragment and a MapActivity.
How can I solve it?
There is no support for MapFragment, Android team says is working on it since Android 3.0. Here more information about the issue http://code.google.com/p/android/issues/detail?id=15347&utm_source=buffer&buffer_share=acc72
But what you can do is create a Fragment that returns a MapActivity. Here is a code example. Thanks to inazaruk: https://github.com/inazaruk/examples/tree/master/MapFragmentExample
How it works:
MainFragmentActivity is the activity that extends FragmentActivity
and hosts two MapFragments.
MyMapActivity extends MapActivity and
has MapView.
LocalActivityManagerFragment hosts
LocalActivityManager.
MyMapFragment extends LocalActivityManagerFragment and with help of TabHost creates
internal instance of MyMapActivity.
if you have any doubt please let me know
Google released the Map API Version 2. This finally allows us to use a MapFragment and a SupportMapFragment. This allows adding Maps to ViewPagers and to Activities that do not extend MapActivity.