Android Inflate Layout With its Own Activity - android

Good Day everyone.I have searched internet and hardly found that it can't be like that but i really can't believe.So i decided to ask here whether is it possible to inflate layout which will have its own activity i mean JAVA CLASS where i would type the code.So just for this case.Imagine we must have google maps on screen and as well as separate screen of list view people all nearby.So in that point we want to inflate the layout onto google maps view.But as i can logically think it will be horrible to write code all in one class by side of performance,so I'm looking for alternatives to inflating a layout,is somehow we can bring activity on main screen and don't lose that screen as well?This is all questions.Thank you very much beforehand!

If I have understood you right, you want to have two layouts in one Activity?
You should use Fragments for it purpose. You can add as many as you want in one Activity, and manage them dynamically. You can find solution here. Also, look at this solution.

Related

What is the best way to build app architecture( activities and fragments)

I am building app right now. I am trying to follow all design patterns and google suggestions for building responsive apps.
Firstly, my app will contain navigation drawer.Of course my app will have several activities. So I have searched the best way to have navigation drawer on all activities, I found that the most correct way is to use some BaseActivity class which will have navigation drawer in its layout and framelaout for storing each activity representation(container for fragment). It can hold fragment, but the problem is that only one fragment.
So I have faced this problem. I am going to design following activity
So as in the picture I wanna to have image slider at the top , and some other layout parts under this slider for example grid layout, list or something other.
I think it would be better to separate image slider and other part, for example when my scree will be in landscape orientation it should be replaced but something other.
Futhermore others activites also gonna to have several independent parts for example list and anything other widget.
But as far as my activities should extend BaseActivity class, they would have only one place(container) for storing fragment.
I have tried to think about ways to solve this problem , and I have only one idea is to create several fram layouts in base activity(equal to max fragments used on child activities) and setting them visible and invisible depending on needs, but this approach pretended to be only way of hidding problem.
I don't know what is the most correct way to implement such type of application, so I need help or advices from more experienced developers to build my app correctly and bring user good experience.
I hope you can help me.
Thanks.
To start with, the container in your BaseActivity does not have to necessarily be a FrameLayout. For example it could easily be a LinearLayout with android:orientation="vertical", so that all fragments you add in it will stack one below the other.
Also each fragment can has other nested fragments in itself (although that's generally not the best practice, as usually it indicates some bad UX decisions).
Both those said, I think you just use the first point I made here. Now if you choose this one, I'd expect the question how to handle tablets and other big screens? Best way to handle them is to create a new landscape layout for your BaseActivity, where the fragments container might be different, for example a RelativeLayout, a LinearLayout with orientation="horizontal" and so on.
Good luck!

A view for a game without a layout

I'm at the beginning of my development for my game and I have a basic question.
Is the layout necessary for displaying a view?
I have the method which allows me to make the toolbar disappear and set the view screen wide, but it seems a bit useless to do so.
Besides in the snake sample provided in the sdk, the views are merged without a layout.
So, which one is the best practice.
And if it's the layout-less solution, how to do for a unique view to display?
Thanks.
Well, I am as new as you are too, but as far as I have searched and learned online and with a few examples, all I can say is, NO. Game programming does not need any xml layouts. For developing a game, you need to first create a good basic framework. All the views, sprites, actions, audio, etc... is created at background.
This is a very nice tutorial to start with.
It depends on lots of things, but yes you don't need to create an XML layout. Pay attention to the word XML. You can create a custom class which extends SurfaceView and work in cooperate with Thread to do the update. So in this case you just need to set your Activity's Content View to this subclass of SurfaceView. But by using SurfaceView you have a raw of context which means you should do everything from stratch, e.g you should implement your own button.
Beside this it depends on the engine/framework you use too. But for SurfaceView/Canvas API the lines I mentioned above is valid.

Android: more than 80 views; Viewflipper or Fragments (or something else..)

I'm building an app where you can edit a detailspage. Right now I set the visibility to GONE and to VISIBLE because all the Views (for showing and for editing) are in the same xml file.
That makes more than 80 views, so I got a Lint message that this causes bad performance.
My Question is cann I use ViewFlipper (and is it possible to use two xmls for this) or do I better make use of two Fragments?
(fyi: I am also planning a animation between showing and editing, if that changes what I better do)
thx in Advance
You do not need either: a ViewFlipper or two fragments introduce unnecessary complications. I would separate showing and editing on different layouts (one XML file for each), and construct a different activity with each layout. When the user clicks on "edit" start the new activity (with an intent) and go to the edit screen. Then after saving the data just finish() the activity.
That is what we do, and it works great! Sometimes the "easy" solution is the best one, as in this case.
As to the animation part, there are already great answers here on Stack Overflow, such as here or here.
In case you want to keep the ActionBar while you animate between show and edit, two fragments would seem like the way to go. You can also have two layouts and inflate them independently, so that you don't accumulate so many views in one layout. Keep in mind however that (unless you create the ActionBar and fragments yourself) you will be limiting yourself to Honeycomb 3.0 and beyond.

Swipe for activities in Android

I am trying to build an app in which I want to go to a new page through swipe-say. I have about 10 different pages and I want to go to these pages by swiping. Can I implement these pages as separate activities? Can I swipe from one activity to another? I strongly like to implement these pages in seperate xml files rather than creating everything in a single xml page. But as far as I have searched, there are no proper tutorials or blogs giving an appropriate example of a program implementing swipe. If possible, provide some working codes.
Thanks in advance.
It seems that a FragmentPager is what you want.
Examples and code on the linked page.
If you build for earlier versions of Android, the necessary code is included in the Android Support Package.
In Android, swipe is not identified as a particular gesture.
You can use a OnTouchListener registered on your view, and animate your view if the gesture exeeds a certain threshold.
You can then launch a new activity, or in a simpler way, use a viewFlipper.
Please try the attached link View flow.
I feel it will fit your needs perfectly. You can even create different xmls and inflate them into different view objects and then use the "view flow" to switch between them.
The "view flow" is perfect for handling both simple & complicated views. The flow indicator on the top of the screen is optional.
I hope it helps..

android: how to create multiply views screen?

I want to create an activity, which shows a question with 4 answers, and at the bottom of the screen i want to place a timer.
I have already found timer example, and i created a question with the answers. the problem that they are 2 different projects and activities, and i am looking for the best way to implement it. i think i can't show 2 activities on one screen, but i can show 2 views or shell i use the ViewGroup, or maybe to copy-paste one of the activities code to another ( its the easiest way but probably the most ugliest way to implement it).
please tell me what is the best way, that i will study and not to waste time to study all the ways and only then to choose one of them.
welcome to StackOverflow.
You are correct in that you cannot display two activities at once. You must instead look into how layouts work in Android by reading some tutorials on the Android developer guide.
For your layout, I would recommend using a LinearLayout with four TextView objects inside it containing the questions (and perhaps your EditText objects below them) as well as your timer. Make sure they are all inside a ScrollView so the software keyboard doesn't force it all to be squeezed up. This is how I would approach it, but I encourage you to read about how layouts work and use the XML resources.
The Notepad tutorial is an excellent way to get started with views and text entry, as well as using SQLite databases.

Categories

Resources