Just I have created graph chart using Chart Engine Android
I have used data from my database to use value for chart.
Now I have one activity which is main to display graph chart with left menu options.
So Whenever i am calling chart activity its going to show its own activity sepratly.
I want to embed that chart activity with my main activity with left menu options.
Is it possible? I am using android 4.0
How to solve this task? Please help me friends.
It sounds like your application would benefit from using Fragments The developer site has some very good information you should read.
You can't embed an Activity into another in Android, as Activities are meant to be independent objects.
Since android 3.0, you can use Fragments, which are Activities sub-elements, which you can combine in many different way. For example having your Activity using one left fragment to display a list of items and a right fragment to display the details of the selected item.
You should take a look at the Fragements documentation to implement this in your application.
Try Activity Group.
http://developer.android.com/reference/android/app/ActivityGroup.html
Related
I searched through the site but could not find an answer so here is my question.
I am using Android Studio 3.6 and when I start a new project and choose Basic Activity there are two fragments appearing in layout. So in layout there are .xml files activity_main,content_main,fragment_first and fragment_second. Therefore, when I start a new project, I get a different screen than the usual "hello world" screen. To add, I cannot basically edit the fragments. So, how can I back to "normal" and start without these fragments?
When you create a basic activity, you basically create an activity with two fragments. this means that basic activity by default provides two fragments that you can edit and use. basically, it's almost the same with bottom navigation activity. the difference is only in basic activity there is no bottom navigation.
if you want to make one activity app. you don't really need to use fragments. so you can just make a Empty activity instead of basic activity. if you want to make your activity fragmented in the future, you can add it later.
I have 2 activities, In first activity I have a button and I want when user clicks or move up that button the second activity come from bottom and stop when it goes to the half of the screen. I don't understand how can I achieve this. I also searched google but they show some type of dialog boxes :(.
This is what I want. When app start 1st activity is shown on the screen but when user click ^ this button both 2 activities show 50% on the screen.
Can anybody tell me how can I achieve this. Is it possible???
You would achieve this using Fragments.
I would suggest you start with the offical documentation - https://developer.android.com/training/basics/fragments/index.html
In order to create the interface above you could use fragments instead of activity.
In your case you need to have an activity with two fragments (you can use coordinatorlayout).
If you don't have enough knowledge about fragments I recommend to read those articles:
Codepath fragments guide
Vogella fragments guide
Convert Activity to Fragment and use <FrameLayout> on page to display/remove fragments from page.
Fragments are reusable components Refer to convert Activity to Fragment
This might help you understand how to work with Fragments link
You should read about fragments. They can be used for the UI you described. You can make it so that a second fragment is GONE, and when the user presses a button, it becomes visible. You should probably use a relative layout for the two fragments.
I have seen a few questions raised on this topic (for e.g.: https://github.com/jfeinstein10/SlidingMenu/issues/5) but I am still unclear. I hope somebody can clarify this.
Context:
See https://github.com/jfeinstein10/SlidingMenu
I have an android app that organizes screens by activities and fragments (i.e.) each screen is an activity containing one or more fragments.
The new requirement is to add a sliding menu (similar to what this library provides).
Issue:
It appears from the examples and discussion that the right model would be to have just 1 MAIN ACTIVITY that will then switch in/out fragments belonging to the different screens. In fact the author mentions in the above thread: "If you were to launch Activities based upon the list selection, then you would not have the behavior where you swap the views that you're talking about. " and also "You can't put an Activity into the above view. That doesn't really make sense when you think about what an Activity is. ".
Why doesn't it make sense? Obviously, I am missing the point here.
Question:
Given that my project already contains multiple activities (one corresponding to each screen), is my only option then to re-organize the project to have JUST 1 MAIN ACTIVITY, in order to use this library? Or alternatively, is there any way to launch a new activity when a list item in the sliding menu is clicked, and still observe the sliding menu behavior, [EDIT- added the last part to be more clear] or in other words, on how exactly to use this library within my existing app design.
Thanks in advance
First, you can't have an Activity inside another and activities are completely different from views as stated in the docs:
An activity is a single, focused thing that the user can do.
Now, to answer your question, it all depends on how you want your app to behave. You could have your activities with the sliding menu implement the onClosedListener and switch to the selected activity from there. This will give you the animation of closing the menu before switching activities. It will also give you a weird effect since every time you select something from your menu you'll see the animation of a new activity coming to the front.
I think the best approach would be to have a "common purpose" between all your sliding menu options. For example, in one of my projects I have to allow the users to select between lists of different types of data. When the user selects anything from the menu, I load a new list fragment into the right corner where he may choose the item he wants to view or edit. That's the app entry point and also the only place were I have a sliding menu in my app. It is pretty much the same for every app that implements this UI design pattern. Look at google+, currents and youtube where the side menu lets you choose which feed or content to show. Once a user makes a selection, just open a new activity for the selected item (a g+ post, a video, a news article, a tweet or whatever it is).
Your app doesn't have to have lists of different data or anything like that to use the sliding menu, but keep in mind that the activity with the sliding menu should have a clear, focused goal with respect to its functionality and purpose. Having a sliding menu because many other apps have one is a bad choice, you should use it with a specific objective. Also keep in mind that applying the sliding menu everywhere would interfere with the platform's navigation pattern and lead to an overall bad user experience since it wouldn't behave as the other apps.
It doesn't make sense to place an Activity into the above view because the Activity is the main controller for the view of each screen. The Activity also shows views and keeps track of Fragments (which in turn are mini controllers, with or without their own views). So placing an Activity in the above view would mean that you would place an Activity in an Activity... Wich is impossible.
From what I can derive from your text I think it would be wise to read through the Android developer guide on Activities and Fragment again (http://developer.android.com/guide/components/activities.html) to get a better understanding of how the concept of Android works.
Now to your question:
I am not clear on what you are trying to achieve but if you want your app, with menu to behave like, say, the Google+ app then one way of doing it is to implement a base class that extends the Activity class (or what ever base Activity used in your project) and let the base set the SlidingMenu. Then you would simple extend your base Activity in each of the Activities that are supposed to have a menu.
You could also do it the way you describe it, but then you would end up with a classic example of a God object (http://en.wikipedia.org/wiki/God_object). It's a neat way to practice your Fragment juggling skills and switching between Fragments instead of starting new Activities does have it's use cases, but I still wouldn't recommend it for a project with more then a few views.
Here is the answer that came closest to the issue I had - http://www.verious.com/article/polishing-the-sliding-app-menu/. Scroll down to the bottom of the page to see the last section titled "Using the fly-in app menu between Activities". This is one option if you have a lot of activities in your existing app and want to avoid extensive re-factoring. I haven't tried this out yet but its worth being aware of.
Can we make use of multiple Activity classes in a single screen of Android app?
For example, make use of multiple Activity classes to call different web services and populate information on the screen?
A activity represents one screen on android. I think Fragments are what you search for. With Fragments you can show more layouts on one screen.
I am trying to create an app to work on both tablet and legacy phones that adds fragments dynamically based on user interaction. An example of an app that mimics this logic is called pulse
When the user selects a news source, it is dynamically added to the bottom. I am wondering how this is done. Do I have to create new activity every time a new fragment is added?
Anyone, please advise. An example would be duly appreciated.
No, you don't need to create activity. You can add, remove, hide and show fragments in current activity.
Please read Fragment documentation and take a look at FragmentTransaction.
Refer GoogleIO,CheckoutLink this explains how add fragment dynamically