i have TabHost app with Three Activities,in first tab i created a viewGroup.every thing working fine
my problem is i want to get TabActivity instance from the view group's chaild Activity
How can i get this... i am trying like this in View group's child activity
Tab_Activity TabObj = (Tab_Activity)getParent();
abObj.someMethod();
i got Class Cast Exception,i think i am getting View group Activity instance,
i want to get TabActivity instance,please help me if any one knows answer
Tab_Activity TabObj = (Tab_Activity)getParent().getParent();
treid like this also...
Thanx in Advance
I just tested it: if your TabActivity properly extends the standard android.app.TabActivity then Tab_Activity TabObj = (Tab_Activity)getParent(); should work as designed.
EDIT: AH. You want to do something like this:
Tab_Activity TabObj = (Tab_Activity)((ChildActivity)getContext()).getParent();
from inside the ViewGroup.
Related
Sorry I recreate my post and PLZ this time just answer if you know or have an idea about the answer, i'm tired about people answering "Why you do that ?" Or "Omg you don't know Android ?".
In my MainActivity (extends Activity), i want to call my class ListDataView (extends View) which displays a ListView.
Is it possible ? Don't ask me why i want to do that, just answer Yes or No and Why plz.
TY
ps : sry for my behavior, but really tired about some useless guys in this community.
What you really want?
In your mainView show the ListDataView: You should check the fragments I think that it is that you really want to do. https://stackoverflow.com/questions/5710573/need-a-fragments-example
Add a button (for example) to go to the other view: create a new activity with the new view and do an intent. http://www.vogella.com/articles/AndroidIntent/article.html
Hope it will helps you.
so you have one Activity and one view class called ListDataView that displays a list of data. and you want to set ListDataView as the view of your activity. Please correct me if my understanding is not correct..
You can create a object of your class ListDataView and set that object as the view of the Activity by using setContentView() method as shown in the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
ListDataView view = new ListDataView(this);
//may be some initialization of the ListDataView
setContentView(view)
}
I am creating an android project . In that i i got the ids from the XML file and wrote the click events in a (class or activity) . I want to use the widgets from another class without getting the id's again. like (Button btn=(Button)findViewById(R.id.button1);) i want to use this code in one class
But I want to use the Button btn in another class and also the click event should work.
If you want to use any View in more than one Activity you can create a class BaseActivity that extends Activity and include all the common Views in that Activity and then extend this BaseActivity to all the Activity in which you want to use common views/layouts/headers/footers. For a Pseudo code you can check my answer here.
I have an Android application which has four tabs (I use a main TabActivity with TabHost and TabSpecs).
In one of my sub activity (activity opened in a tab), i need to open a tab not by clicking on the tab title and i don't know how to do this.
For example, i have a button in my activity and when i click on it, it opens a different tab.
For the moment, it is what i do:
Intent intent = new Intent(myActivity.this, myTabActivity.class);
intent.putExtra("ComeFrom", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Then in the TabActivity, if i get true reading the "ComeFrom" extra i open the wished tab but the problem is that it kills all the other activies. So, if someone knows a better (cleaner) way to do that trick, please tell me...
Found an easier (I think) answer:
on the TabActivity declare a public, static and self variable and populate it on the onCreate method. F.e.:
public class TheActivity extends TabActivity {
public static TheActivity self;
...
#Override
public void onCreate(Bundle savedInstanceState) {
self=this;
on any Activity running in a tab, when you want to change the one shown on your app. you can do this:
TabHost tabHost = TheActivity.self.getTabHost();
tabHost.setCurrentTab(0);
Worked ok for me, hope serves someone else!
You have to use TabHost's "setCurrentTab(...)" for that. In one of my projects, I created a static method in the main Activity (the one with the TabHost), named "swtichToTab(int tab)". In my subactivites (those inside the tabs) could then just call "MainActivity.switchToTab()" to trigger switching.
It may not be the cleanest method, I'm sure you can achieve this using broadcast intents too.
You can create a BroadcastReceiver and send a broadcast with the index of the tab as extra
You can use views instead of activities for the content of the tabs. This way, the code is simpler and doesn't use as much memory. Plus, you then can use the setCurrentTab(tabIndex) method to easily switch between views.
I have a simple tutorial here. It has a tab activity with a list and map view. When you you click on an item in the list, the activity dynamically goes to the map view (using the setCurrentTab(tabIndex) method). You can easily modify this to have a button switch views.
I would like to access the public method of an Activity run by a TabActivity using:
TabHost tabHost = getTabHost();
Intent intentMsgsView = new Intent().setClass(this, TeamHuddleScreenMsgsView.class);
tabHost.addTab(tabHost.newTabSpec("msgs").setIndicator("Messages").setContent(intentMsgsView));
Basically, what I what is to let the parent Activity call a method in child Activity in order to do something. Is this possible?
I did try this:
((TeamHuddleScreenMsgsView)getTabHost().getCurrentTabView().getContext()).refreshModel();
but I'm encountering a ClassCastException. It seems that the getContext() still gives the TabActivity. Any help on how to get the child Activity?
Thanks.
Listen to what CommonsWare says here, I have gone this route and it was a horrible mistake, but here is how you do it.
((SportsActivity)getLocalActivityManager().getCurrentActivity()).setLayout(R.layout.helpview);
Here setLayout is a public method I made in SportsActivity
This will be much simpler if you would not put activities in your tabs and just put views in your tabs, as that will mean there is only one activity. Here is a sample project showing how this is done.
There is a getActivity() method on ActivityGroup (parent class of TabActivity) that is undocumented but might be what you want.
I want to know if we can display multiple activities in a single activity using ActivityGroup.
Can anyone please help me out with this ?
Thanks in advance.
Regards,
Serenity.
extend it to your activitygroup class.
Class A extends ActivityGroup{}
Get the LocalActivityManager
Set the content view as shown below
this.setContentView(activity.getWindow().getDecorView());
Where activity -> reference of the activity which you would like to display.
Class B extends Activity{
//in onCreate()
Activity activity = this;
}
As seen in coderanch.com