Android set constant Button in more than 5 activity - android

Hi I am new to Android I want to Set One Button named (Click) in More than Five Activity like Title of the Application at the Top.I did not want it to add on all the 5 activity Manually is there any simple way in Android?

This is simple if you have one layout for all 5 activities, but you probably don't. So the solution is to create 5 buttons in each layout with same id. Then you can create a static method in one of your activities called, for example, initializeButton(). This method should inflate your button. You can call this method from every activity, and it should do the job. Hope this helps.

Related

How can i update an activity in android studio

I've created an app with two activities. On the second activity i can create new buttons by pressing a floating action bar button inside the activity; but the problems is when i return to the main activity and come back all the added buttons are gone.
I was wondering how can i save these added views so whenever i exit that particular activity or the app entirely, views won't perish.
I know i can save the views' values by "Preferences" commands but that only can save the views' parameters not themselves and if i go that way i have to recreate each view again each time i enter the activity.
if i could update the activity whenever views are added to it that would be excellent.
I would appreciate any help.
You can save information about views in preference like number of buttons created. for example you clicked button 4 times then save numOfButtons value as 4. In onCreate method you can check values of numOfButtons and execute that block of code 4 times to generate buttons.

Whether it is possible to use two activities with same layout

Whether it is possible one layout can be called by two activities.
Say i have a textview and a button.
1) Using one activity i set the textView with a name
2) Using another activity, is it possible to display popup message when i click the button.
first activity should set the textview alone and second activity should be called when i click the button. Because, i will get the text from api webservice call in first activity and will display message in popup window using another activity using some other api webservice call.
yes you can use one layout for two activities,but in that case where you use same controls for both activites:
like activity one:
uses both one textView and Button
like activity two:
uses both one textView and Button
Yes. Two activities don't care if they are using the same layout, and in fact don't really know about it. You can use view.setVisibility to make certain views invisible or visible, and as long as you are using the ids associated with the views can make different calls on them in the activities.
So the answer is yes, you can manipulate that layout however you like in two different activities.
No problem, you can easily use same layout file for more then one activity.
First try to implement this thing in your project, and then see, what happening.
Thanks,
Sumeet.

Android - How to change Activities within a TabActivity?

I currently have a TabActivity which has 4 tabs, within one of the tab's I want to be able to move forward and back between 4 different Activities.
However if I try to start a new Activity now it removes the TabActivty and starts a whole new Activity with no tab bars.
I have read about using view groups but that this is not best practice and also about using a view flipper but this doesn't seem to let me switch between different Activities only change the views within the Activity. I can't implement back functionality for exa,ple.
Can anyone point me in the right direction as to what I should be looking for as a solution to this?
EDIT:
Some more information:
Within the TabActivity my first screen will be a ListView that contains 4 rows, then selecting one of these will in turn load another ListView with 2 rows again within the TabActivity and then the 3rd screen will just contain some text depending on which option the user chose again within the Tab Activity.
Is a ViewFlipper the best solution here? It seems to me that it will require a lot of coding within one Activity if I use the ViewFlipper?
I have done something similar. I used the ViewFlipper to achieve this. You can override onBackPressed in your Activity so you can deal with moving back through your views.
There's a couple of ways of doing this but a simple way would be to just increment a counter in your Activity as you move to the next views, then in your onBackPressed method if counter != 0 just show the previous view, if counter == 0 call super.onBackPressed.
You can see in my video showing what the result could look like (ignore the bug being shown in the video).

run time layout manipulation

I have a grid type of layout. When the app first loads, there are 3 buttons. I am using "Adapter" for the layout.
ONCLICK of the button, I want to refresh the same activity but with different set of 9 buttons.
Do I start a new Activity in all? OR Make a temporary activity to start the previous activity (and how)?
Since the ONCLICK event is written in the "Adapter" part of the code, starting new activity on click of the button is difficult. (is out of my knowledge).
if you are using adapter i.e., like baseadapter then you can try:
adapter.notifyDataSetChanged();
directly without starting activity again.
If you want the user to go back to the 3 button view on click of Back button, it will be easier to have the 9 buttons in a different Activity.
Otherwise, you can have the 3 buttons and 9 buttons within two different LinearLayouts in the same activity and hide the second layout using setVisibility(LinearLayout.GONE);
On Click of the button, you can hide the first layout and enable the second one using setVisibility(LinearLayout.VISIBLE);
In the adapter class, we can start an activity using context.startActivity(intent) I did not know that we can access "start Activity" from adapter...
but now it's working just fine!!
Thanks a lot for your recommendation...

Android how to change views?

Basically I need some suggestions which is the best way to switch views in my situation. My Application has 5 different tabs. In every single tab I'm using activity manager to start as many activities that I need inside this tab. Now I have a little problem. In one of the tabs I need to create something like three different tabs. In second tabs I used 3 buttons, which switch the views via viewflipper. But now I have like 2 or 3 views inside every new tab (or button) which I need to switch. I did it with viewflipper but it's actually not what I want, because I want to use back button to switch between views.
Example:
MAIN TAB BAR : ONE TWO THREE FOUR FIVE
SECOND TAB BAR INSIDE TAB THREE / OR JUST THREE BUTTONS : TAB-A TAB-B TAB-C
IN TAB-A I have only one view.
IN TAB-B I have 2 views. View 1 is a listView and onItemClick switch view 2.
IN TAB-C I have same scenario like in TAB-B.
P.S. View 1 and View 2 directly can change to TAB-C.And I need to be able to send data between the views/activities.
Any suggestions how to do that? ViewFlipper or something else.
Better use activities inside the tab THREE and create three buttons which starts new activity.And you can use ViewFlipper inside these activities to change the views,or viewswticher.It depends on your needs.
You can override the onBackPressed in your activity to change the default behaviour of the back button
http://developer.android.com/reference/android/app/Activity.html#onBackPressed()

Categories

Resources