简体   繁体   中英

Android 2.3.3, layout loading with tabhost and second tabhost not working

Below is a picture of what i want.

在此处输入图片说明

Right now. When i click on an item (see 2 in image) then the incorrect version (see 3 in image) shows up.

How can i load the second tabhost (see 3 in image) into the framelayout of the first tabhost?

Code right now (resides in 2, see picture) (that produces the incorrect layout) is this:

listView.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {

                Intent i = new Intent(StaticResources.FrameContainer.getContext(), AppSecondTabHost.class);
                StaticResources.FrameContainer.getContext().startActivity(i);
            }
        });

The static variable: StaticResources.FrameContainer is set in the main activity (see 1 in image) like this:

StaticResources.FrameContainer = (View)getTabHost().getTabContentView();

Any idea how i can rewrite the onitem click event to display the correct version? The bottom right version with 2 tabhosts as seen on the picture.

EDIT

To be extra clear. I create the tabhost in pic 1. When i click on one of the tabs an activity starts and that activity displays a list (picture 2). When i THEN click on an item in this list, this item will store its id in an intent and open a second tabhost inside the first tabhost (picture 3-4). The second tabhost (picture 3) will then read the id that was set in picture 2 in the onitemclick event.

if you are using tabhost, it will automatically handle all the tab click events if you add all the tabs onto the tabhost. you do not need to change the tabview manually using an onClickListener.

below is an example from my application:

    intent = new Intent().setClass(this, deployment.class);
    intent.putExtra("deploy_data", deployRawData);

    spec = tabHost.newTabSpec("Deployment").setIndicator("Deployment",
                      res.getDrawable(R.drawable.man))
                  .setContent(intent);

    tabHost.addTab(spec);

in this way, you are essentially bundling the activity and the tabview together before adding onto the tabhost. it should help you save a lot of efforts coding the onClickListener.

 TabHost tabHost=getTabHost();
    TabHost.TabSpec tabSpec;
    Resources res=getResources();

    tabSpec=tabHost.newTabSpec("First");
    tabSpec.setIndicator("FirstTabName",res.getDrawable(R.drawable.image));
    Intent i1=new Intent(this,NextClass.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    tabSpec.setContent(i1);
    tabHost.addTab(tabSpec);

Like this, you define Intent to the tab. So your tab will remain constant and bottom content will be that of your activity.

On selecting an item from the list, intent it to next class where you have a different layout with only two tabs. .

TabHost tabHost=getTabHost(); TabHost.TabSpec tabSpec; Resources res=getResources();

tabSpec=tabHost.newTabSpec("First"); tabSpec.setIndicator("FirstTabName",res.getDrawable(R.drawable.image)); Intent i1=new Intent(this,NextClass.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); tabSpec.setContent(i1); tabHost.addTab(tabSpec);

Like this, you define Intent to the tab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM