I am learning Android Studio and I have recently come across listview.
I am making a project which has 6 buttons and each of those 6 buttons will open an activity where there are 2 additional buttons and if you click on 1 of those 2 activities you will reach the required page.The required pages have different text content.
I am approaching this problem by creating a new xml file for every activity however this leads to creation of many pages and I just wanted to know if there is any method which will reduce the number of files created for this project
If your two activity have similar look than you can use same layout,
else you have to create different layouts for all your activity.
If you have Activities that looks alike you can use the same layout file for both activities, and only change the behavior in the Java side.
And if you have activities thats acts alike you can also use the same activity and change the behavior depending on some extras.
Related
I have to make a new design for an Android App, but I only have to create the visual part (native Android). The app logic would be created by another guy based on what I present to him.
My question is? How would this be managed correctly? Do I have to make the XML's of each layout? How could I show the other person my progress?
What things should I consider when doing this?
Thanks
You need to mock the app first (create a prototype) as suggested by NoChinDeluxe. Then if you guys go ahead and decide to code it, the answer to your problem is separation of responsibilities. As Jeffrey said UI work is not only about layouts, but code as well. What I would suggest is that you and the other guy get together first and define some contracts (interfaces) that will allow you guys to split the work and work in parallel. Therefore, he can create the business logic of the app without worrying about the UI implementation. You, on the other hand, will have to mock that business logic he's implementing at the beginning so it doesn't block your UI work.
you could create layout XML files for all the Activities/screens, using resources (icons, etc as suggested by #NoChinDeluxe). However since you'd want to run the mock app, you might want to also create a "throw-away" Activity that allows you navigate to different screens of the app. Here you can add a number of buttons and when you click on each button, your app shows a specific activity. This way, you will be able to show your colleague all the screens you have created. I hope this helps.
This may not be what you want to hear, but creating Android layouts isn't a design task. They are closely tied to the code, and the design of them is going to depend on how the engineer chooses to implement the app.
Here's an example. You might have a grid with 4 cells. You could use a RelativeLayout, a LinearLayout, or GridLayout, or a GridViewLayout. Which will use choose?
I'd suggest providing your engineer with mockups and graphical assets where required. Let him / her take those and create the layouts. If you want to create layouts as a (visual-only) reference for engineering, great, but it's certainly a non-optimal tool for that task.
Things You will consider when doing visual part:-
You have to work on the resource folder of your application
Layout : All Layout you have to prepare.
Drawable : Images and drawable .xml.
Inside Values folder you will find
dimen.xml : For different devices dimen you can set.
string.xml : You can store string for hint or other purpose.
style.xml : For designing or theme or custom design.
color.xml : Color which are going to used in the application.
Im developing an application with quite a number of activities.
The activities are content wise identical, containing 2 buttons and 2 textfields.
The problem I have is that I want every activity to look like every other in placement, since their content will be different.
Im using the Eclipse IDE
How do I approach this problem?
You should share one layout with different activities. Create a layout (xml file) and then use it for all the activities that you want to look identical. Just change setContentView(R.layout.yourlayout); in onCreate().
I'm building an Android App which has a complex screen with lots of logic.
It currently contains a listview, tabs, search box, and a panel for updating user stuff.
The probem is that the mainactivity code file became very big, although I'm seperating things to different layers, because there's a lot of UI components which affect things in the screen.
I'm trying to seperate it to several files but I don't seem to do it right.
As much as I understood Fragments is not what I need here. Are there any other ways?
Just need some directions please.
I'm asking mostly about the code, not the layout (Although I don't care changing the layout too).
Currently it's 616 lines and the biggest problem is that we are a team and the maintenance became hell...
Create utility class and put your listeners and adapters there. Use main activity only to initialise view instances and setting listeners and adapters.
Although 616 is not a particularly big file you could use Fragments as they just add another layer of abstraction. They also have a similar lifecycle to activities.
This tutorial shows how to add fragments to tabs
http://developer.android.com/training/implementing-navigation/lateral.html
You can create a base class put all the initializations and listerners there.
Likewise for function to be implemented later create a template in base class and override it in main activity. It works !
We have an Android application made of menu of modules and each module has the same layout as on this picture:
You have a header with module name and two buttons on the bottom. The module itself is behind those three transparent elements. Left button allows the user to move to the previous screen and right button gets him back to the menu with modules. Text in header changes based on current screen action.
My question is how to build the module transparent frame. Is it possible to have one layout in Android on top of the other? Should we design the code as a parent class that would be inherited by all the modules? I am interested in some best practice. I have experience with Java but only theoretical knowledge of Android.
Prepare a separate common layout and use to add that layout to as many layouts you want.
for more details check this
What you are looking for are so called Fragments. These Fragments are sort of like Activities, with their own layouts and lifecycles, but you are able to use multiple Fragments at once. This means you'll be able to use one Fragment for your navigation and header, and one for the module behind it.
I am beginner in android development and my problem is that ı want to add some buttons in runtime. I mean, number of button will be change according to flow of program so i need to create different number of buttons at different situations. In code section i can handle it by using array but what about layout file? how can ı set the layout file according to flow of program. I hope ı could explain my problem. Thank you very much.
The xml files in res/layout are static descriptions of layouts. You can create different ones to be used in different contexts (different activities, dialogs, etc). You can actually even replace one layout with another one in the same activity. What you cannot do is to modify the xml files during runtime.
If your UI depends on runtime variables, then you will have to act accordingly. If it's just the number of buttons that will change, you can either
Add new buttons using addView(button);
Add a ListView to your xml file and use an ArrayList and an ArrayAdapter to determine how many buttons you will need.