I am having 2 activities, in each activity I am having a view-flipper and button. When the button in 1st activity is clicked, I want to view the 2nd activity's view-flipper child. How to do that? Is that Possible? If yes, please tell me how to do that.
Thanks in advance.
You cannot directly interact with views between activities. Instead, you should pass data in an Intent when you call startActivity() from the first activity. The data should tell the second activity which view to start with. For example, you can send the name or index of the view. You can learn more about sending data in an Intent from the official Android documentation.
Related
Consider we have two Activies: Activity A and Activity B, both have an ImageView. If we click on ImageView in Activity A, ImageView in Activity B should change to another image. Please tell us, how to achieve this by using interface
Your timely suggestions will help us a lot
Send some info about the clicked image in Activity A to Activity B using Intent. Then based on that info show the corresponding image in Activity B
As i understand what you are asking for has been asked many times. Its how to send data between activities. Here is an answer from another thread. Also you can check the Android documentation and read about bundles.
i am struggling to keep data or items of list view when i leave one activity to another, for my example i created simple app on click will add number increased to a list view so each click create an item like 1 another click add 2 and so on.
the program works fin for main activity but then i would like to see the result on another activity i call it second activity but the problem is when i hit back button on second activity to go back to main activity, i will lose all of items on the list view.
i was looking on google so many information but could not get my head around it, so please advice and please be little more in detail as i am beginner, i think instance state or shared preference will do the job but i do not know any of them
thanks in advance and here is my app code for main activity and second activity and picture for output
sorry i add code as images becausethe site keep saying the code need indentation thank you
main activity[main out put][2]second activity[second activity out put][4]
You need to save the data of the ListView in some form, either in a file or in a database (local or remote).There is no direct way to store list view, but you can store the data from the list view and then set it in to the ListView later when you switch back to the activity.
You need to keep in mind that switching activity results to invoking of onPause() method in android, and if the data is not saved in the current activity then it will be lost when you move on to another activity.
Add all your values into the array, pass it to the adapter, then after clicking on the list view item, make an intent where you want to switch your activity (means from one activity to second activity), while implemented the intent, pass your array also, using intent.put extra. Then you will get your array in your second activity and coming back to your previous activity, again pass an intent (with your array) and get your array in your previous activity and pass it into the adapter.
In my app, I create the gridview and then add the view by RelativeLayout LayoutParams.
But how can i call it in another activity?
such as gridview looping the 10 article and hide the icon, i create the edit button to control hide/show the icon. but i dont know how to call it.
Thanks.
Once you switch activities, I don't think you can directly access the ui elements of the previous activity. You should try to send data between activities by creating intents with arguments like this :
Start an Activity with a parameter
If you from activity A to B and you want to pass data back to A, launch A with an intent that has the extra data you need.
Parse the data from the intent and update your UI accordingly.
I am trying to pass a view from one fragment activity to another activity. I am a newbie at Fragments and am not sure if this is possible.
Any thoughts are gladly appreciated.
Thanks.
You don't want to do this, the view will be tied to the activity.
Why do you want to do this, or more specifically what is it you want to achieve?
You can pass information from one activity to another via Intent Extras if you need to recreate the view based on information.
in my app i am having an Activity that launches another Activity ontop of it. The second Activity is meant to provide controls like next and previous for the first activity.
How can i pass button events between the two activities that are visible at the same time without closing the Activity with the controls?
You can send Broadcast in order to communicate between Activities.
In parent Activity register BroadcastReceiver, then send a Broadcast by calling sendBroadcast(..) in child Activity.
It sounds like what you are trying to do doesn't require two activies, but rather additional view objects on the main activity that will be shown/hidden/removed/added as buttons on this activity are pressed.
If you need additional help, I would recommend elaborating on your original post.