current tab tap to go home

Put your problem here if it does not fit any of the other categories.

current tab tap to go home

Postby nocturnalhacker » Thu Mar 01, 2012 10:01 am

In my Android application, the Launcher activity is a TabActivity, where the TabHost contain four TabSpec’s of four TabGroupActivity s. By default every TabGroupActivity start a child activity. The child activities are allowed to navigate so many activities.
In this situation I can navigate the tabs and its works fine. But I want to add a feature so that tap in a current tab will restart the childActivity for that particular tab only.
Any idea or sample code?
User avatar
nocturnalhacker
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 01, 2012 9:58 am

Top

Re: current tab tap to go home

Postby vandzi » Thu Mar 01, 2012 3:53 pm

In child activity move your code from onCreate method to onResume. onResume is called everytime when activity is going to be displayed.
vandzi
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jun 11, 2010 11:31 am
Location: Slovakia

Re: current tab tap to go home

Postby nocturnalhacker » Fri Mar 02, 2012 11:28 pm

Thanks vandzi :)
But in this solution I can’t preserve the current tab state while navigating other tabs.
Another problem is that, if I pressed back, it will get back to previous view (which supposed to be destroyed) from newly on resume view.
Actually what I want is to tap from other tab will show the current taped tab with pre navigated state but if you tap twice ie tap the current selected tap, it will go to home ie GroupActivit’s initial activity.
I have implemented a onclickListener on TabActivity to detect the tap in current tab.
Code: Select all
getTabWidget().getChildAt(0).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getTabHost().getCurrentTabTag().equals("TabGroupActivityOne")) {
                                 // GOT IT
                } else {
                    getTabHost().setCurrentTab(0);
                }
            }
        });

But don’t get idea how to restart the particular TabGroupActivity :(
User avatar
nocturnalhacker
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 01, 2012 9:58 am

Re: current tab tap to go home

Postby nuetronprotron » Sat Mar 03, 2012 7:23 am

Hi nocturnalhacker,
I am sorry that i did not understand about that tab things clearly of what ur requirements are? but as for as single tapping and double tapping is concerned you need to use GuestureDetector instance and then with using that object you can implement what you intended in the respective listeners.


//initialize the Gesture Detector
GuestorDetector gd = new GestureDetector(this);

//set the on Double tap listener
gd.setOnDoubleTapListener(new OnDoubleTapListener()
{
@Override
public boolean onDoubleTap(MotionEvent e)
{
//on double tap functionality
}

@Override
public boolean onDoubleTapEvent(MotionEvent e)
{
//if the second tap hadn't been released and it's being moved
}

@Override
public boolean onSingleTapConfirmed(MotionEvent e)
{
//print a confirmation message and the tap position
}
});



I hope it help you.
nuetronprotron
Developer
Developer
 
Posts: 37
Joined: Tue Jan 10, 2012 10:22 am

Re: current tab tap to go home

Postby nocturnalhacker » Sat Mar 03, 2012 11:39 am

Thanks nuetronprotron :)
Today in the morning I just solved it :D
In my Tab GroupActivity I extend ActivityGroup and write a method (someMethod) to restart.
Then call it from TabActivity
Code: Select all
getTabWidget().getChildAt(0).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getTabHost().getCurrentTabTag().equals("TabGroupActivityOne")) {
                                 FisrtTab currentActivity = (FisrtTab ) getCurrentActivity();
                    currentActivity.someMethod();                } else {
                    getTabHost().setCurrentTab(0);
                }
            }
        });
User avatar
nocturnalhacker
Freshman
Freshman
 
Posts: 6
Joined: Thu Mar 01, 2012 9:58 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests