Patrick
Patrick

Reputation: 5592

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

Below is a picture of what i want.

enter image description here

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.

Upvotes: 0

Views: 1118

Answers (3)

Rashmi.B
Rashmi.B

Reputation: 1787

 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. .

Upvotes: 0

Rashmi.B
Rashmi.B

Reputation: 1787

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.

Upvotes: 0

Scott Meng
Scott Meng

Reputation: 141

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.

Upvotes: 1

Related Questions