タブ ビューと、クリック時に特定のレイアウトを表示するためのいくつかのボタンを含むアクティビティがあります。タブのコンテンツとボタンのクリック時に表示されるコンテンツは、同じコンテンツ領域を共有します。タブビューのコンテンツを作成すると、完全に正常に機能します。ボタンをクリックしてタブ コンテンツのレイアウトを拡張すると、レイアウトが正常に表示されます。タブビューをもう一度クリックして、そのレイアウトを非表示にします。
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;
}
}
};
}
タブ ウィジェットをもう一度クリックしたときにポップアップ レイアウトを非表示にする方法がわかりません。助けてください..事前に感謝します:)