开发者

How to implement double Tabbed Activity in android?

I want to make an android application which has two tap in one view ,i.e, has upper tab and lower tab.

According to selection of lower tab, I add the new tab host(for upper tab) in the tapcontent part of lower tab. But, upper tap doesn't go up, it stick to the lower tab.

The implementation of upper tab is,

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;



 public class uppertab extends TabActivity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);

  setContentView(R.layout.upperlayout);

  TabHost tabHost = getTabHost();
  TabHost.TabSpec spec;
  Intent intent;

  intent = new Intent().setClass(this, recommend_friend_simillar.class);  
  spec = tabHost.newTabSpec("upper1").setIndicator("Upper1").setContent(intent);
  t开发者_如何学GoabHost.addTab(spec);

  intent = new Intent().setClass(this, recommend_friend_new.class);  
  spec = tabHost.newTabSpec("upper2").setIndicator("Upper2").setContent(intent);
  tabHost.addTab(spec);

  intent = new Intent().setClass(this, recommend_friend_favorite.class);  
  spec = tabHost.newTabSpec("upper3").setIndicator("Upper3").setContent(intent);
  tabHost.addTab(spec);

 }
}

xml for upper tap is,

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/uppertabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TabWidget
        android:id="@+id/uppertabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@+id/uppertabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</LinearLayout>

xml for lower tab is,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <TabHost android:id="@android:id/tabhost"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

  <RelativeLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">

   <TabWidget android:id="@android:id/tabs"  
     android:layout_alignParentBottom="true"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       />

      <FrameLayout android:id="@android:id/tabcontent"  
         android:layout_above="@android:id/tabs"
            android:layout_width="fill_parent"  
            android:layout_height="fill_parent">  
   </FrameLayout>
  </RelativeLayout>
  </TabHost>

</LinearLayout>

The result is shown below.

□□□□□□□□□□□□□□□□□□□□□□□□□□
□                        □
□                        □
□                        □
□                        □
□                        □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□       □        □       □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□lower2  □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□

Of course, upper 3 taps should be stick to ceilling, like,

□□□□□□□□□□□□□□□□□□□□□□□□□□
□       □        □       □
□upper1 □ upper2 □ upper3□
□□□□□□□□□□□□□□□□□□□□□□□□□□
□                        □
□                        □
□                        □
□                        □
□                        □
□□□□□□□□□□□□□□□□□□□□□□□□□□
□ lower1□ lower2 □ lower3□
□□□□□□□□□□□□□□□□□□□□□□□□□□

(I got an advice that using activitygroup, but it doesn't work.)

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class uppertab extends ActivityGroup {


 private TabHost tabHost;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.upperlay);

 tabHost = (TabHost)findViewById(R.id.friendtabhost);

 tabHost.setup(getLocalActivityManager());



tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(new Intent(this, tab1.class)));

     tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2").setContent(new Intent(this, tab2.class)));

     tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3").setContent(new Intent(this, tab3.class)));

}

}

DDMS says that

tabHost.setup(getLocalActivityManager());

has a problem.

What can I do :(?


In order to achieve this kind of requirement, where multiple touch events to be generated. You need to design your own control.

Example :- Create and linear layout place one label, place another button on top of it. Now the other control for which you need second tap. All binded together can look like tab simulation. You can have multiple touch elements in one tab and you can get the each touch event triggered seperately.

Best Regards Vinod

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜