0

我有一个包含选项卡视图和几个按钮的活动,用于在单击时显示某些布局。选项卡内容和单击按钮时要显示的内容共享相同的内容区域。在创建我的选项卡视图内容时效果很好。当我单击按钮并在选项卡内容上扩展布局时,布局看起来很好。现在再次单击选项卡视图,我想让该布局不可见。

    import android.app.TabActivity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.LinearLayout.LayoutParams;
    import android.widget.TabHost;
    import android.widget.TabHost.TabSpec;
    import android.widget.TabWidget;
    import android.widget.TextView;

public class Home extends TabActivity{
TabHost mTabHost;

ImageView contactBtn;
LinearLayout popupLayout;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.saintgobain_home);

    ((TabWidget)findViewById(android.R.id.tabs)).setOnClickListener(onclickListener);

    popupLayout=(LinearLayout)findViewById(R.id.popups);

    contactBtn=(ImageView)findViewById(R.id.mailBtn);
    contactBtn.setOnClickListener(onclickListener);

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);


    Intent BuildingIntent = new Intent().setClass(this, HomeScreen.class);
    setupTab(new TextView(this), getResources().getString(R.string.BuildingType_str), BuildingIntent);
    Intent AppIntent = new Intent().setClass(this, ApplicationList.class);
    setupTab(new TextView(this), getResources().getString(R.string.Application_str), AppIntent);
    Intent productIntent = new Intent().setClass(this, ProductScreen.class);
    setupTab(new TextView(this), getResources().getString(R.string.Product_str), productIntent);
    Intent intentDealer = new Intent().setClass(this, DealersActivity.class);
    setupTab(new TextView(this), getResources().getString(R.string.Dealer_str), intentDealer);
}
private void setupTab(final View view, final String tag, Intent intentAndroid) {
    View tabview = createTabView(mTabHost.getContext(), tag);
    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intentAndroid);
    mTabHost.addTab(setContent);
}

private static View createTabView(final Context context, final String text) {
    View view = LayoutInflater.from(context).inflate(R.layout.tab_text, null);
    TextView tv = (TextView) view.findViewById(R.id.tabsText);
    tv.setText(text);
    return view;
}

OnClickListener onclickListener = new OnClickListener() {

    @Override
    public void onClick(View v) {
        switch(v.getId())
        {
        case R.id.mailBtn:
            Log.d("","mailbtn");

                //((FrameLayout)findViewById(android.R.id.tabcontent)).setVisibility(View.INVISIBLE);
                LinearLayout.LayoutParams params= new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
                View view =getLayoutInflater().inflate(R.layout.contact, null);
                popupLayout.addView(view,params);
                popupLayout.setVisibility(View.VISIBLE);                    
            break;  
        case android.R.id.tabs:
            if(popupLayout.getVisibility()==View.VISIBLE);
            {
                popupLayout.setVisibility(View.INVISIBLE);  
            }
            break;
        }
    }
};
}

当我再次单击选项卡小部件时,我不确定如何使弹出布局不可见。请帮助..提前谢谢:)

4

1 回答 1

0

很可能 TabWidget 不听点击...您需要在标签中设置 onClickListener... 像这样:

  for (int i = 0; i < tabs.getTabWidget().getChildCount(); i++) {
        tabs.getTabWidget().getChildAt(i).setOnClickListener(clickListener);
  }
于 2013-06-21T11:59:44.417 回答