有4个fragment fragment之间的切换添加 用 add show hide 来切换。
这里有个一个listview 里面添加了2个headview 在headview的子元素添加onclick事件无效 求解。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = getView();
if (null == view) {
view = inflater.inflate(R.layout.dinneractivity_main, container, false);
ViewUtils.inject(this, view); //注入view和事件
mOperator = new Operator();
super.onCreateView(inflater, container, savedInstanceState);
Tapplication.pullToRefreshListViewMain = pullToRefreshListView;
AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
if (null == adView) {
adView = inflater.inflate(R.layout.home_ad, pullToRefreshListView, false);//首页征集host
mHomeAdClose = (ImageView) adView.findViewById(R.id.home_ad_close);
mHomeAdFrame = (FrameLayout) adView.findViewById(R.id.home_ad_frame);
mHomeAd = (ImageView) adView.findViewById(R.id.home_ad_img);
adView.setLayoutParams(layoutParams);
pullToRefreshListView.getRefreshableView().addHeaderView(adView);
if (HXPreferenceUtils.getInstance().getHomeAdIsShow()) {
mHomeAdFrame.setVisibility(View.VISIBLE);
} else {
mHomeAdFrame.setVisibility(View.GONE);
}
}
//tab切换
if (null == tabView) {
tabView = inflater.inflate(R.layout.home_tab, pullToRefreshListView, false);//首页tab
mChoice = (TextView) tabView.findViewById(R.id.hom_ad_choice);
mChoiceLine = (TextView) tabView.findViewById(R.id.hom_ad_choice_line);
mChoiceEn = (TextView) tabView.findViewById(R.id.hom_ad_choice_text);
mHot = (TextView) tabView.findViewById(R.id.hom_ad_hot);
mHotLine = (TextView) tabView.findViewById(R.id.hom_ad_hot_line);
mHotEn = (TextView) tabView.findViewById(R.id.hom_ad_hot_text);
mTabRt = (RelativeLayout) tabView.findViewById(R.id.home_ad_tab_rt);
mTabChoiceRt = (RelativeLayout) tabView.findViewById(R.id.hom_ad_choice_rt);
mTabHotRt = (RelativeLayout) tabView.findViewById(R.id.hom_ad_hot_rt);
tabView.setLayoutParams(layoutParams);
pullToRefreshListView.getRefreshableView().addHeaderView(tabView);
}
getCache();
}
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null) {
parent.removeView(view);
}
setView(view);
headViewClick();//onclick事件
return view;
}
private void headViewClick() {
View.OnClickListener clickL = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.home_ad_close:
HXPreferenceUtils.getInstance().setHomeAdIsShow(false);
mHomeAdFrame.setVisibility(View.GONE);
break;
case R.id.home_ad_img:
startActivity(new Intent(getActivity(), HomeAdAcitivity.class));
break;
case R.id.hom_ad_choice_rt:
((MainFragmentActivity) getActivity()).topTabSelecte(1);
break;
case R.id.hom_ad_hot_rt:
((MainFragmentActivity) getActivity()).topTabSelecte(2);
break;
}
}
};
mTabChoiceRt.setOnClickListener(clickL);
mTabHotRt.setOnClickListener(clickL);
mHomeAdClose.setOnClickListener(clickL);
mHomeAd.setOnClickListener(clickL);
}