FragmentTabhost记录

<android.support.v4.app.FragmentTabHost

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/tabhost"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TabWidget

android:id="@+id/tabwidget_tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<FrameLayout

android:id="@+id/layout_container_tabcontent"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</android.support.v4.app.FragmentTabHost>


import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTabHost;
import android.view.Menu;
import android.widget.TabHost.TabSpec;

public class MainActivity extends FragmentActivity {
private FragmentTabHost tabHost;
private Bundle bundle1, bundle2, bundle3, bundle4;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (FragmentTabHost) findViewById(R.id.tabhost);
FragmentManager manager = getSupportFragmentManager();
tabHost.setup(this, manager, R.id.layout_container_tabcontent);

TabSpec tabSpec1 = tabHost.newTabSpec("records");
tabSpec1.setIndicator("记录");
bundle1 = new Bundle();
bundle1.putInt("tabIndex", 1);

TabSpec tabSpec2 = tabHost.newTabSpec("contacts");
tabSpec2.setIndicator("联系人");
bundle2 = new Bundle();
bundle2.putInt("tabIndex", 2);

TabSpec tabSpec3 = tabHost.newTabSpec("collections");
tabSpec3.setIndicator("收藏夹");
bundle3 = new Bundle();
bundle3.putInt("tabIndex", 3);

TabSpec tabSpec4 = tabHost.newTabSpec("groups");
tabSpec4.setIndicator("群组");
bundle4 = new Bundle();
bundle4.putInt("tabIndex", 4);

tabHost.addTab(tabSpec1, DummyFragment.class, bundle1);
tabHost.addTab(tabSpec2, DummyFragment.class, bundle2);
tabHost.addTab(tabSpec3, DummyFragment.class, bundle3);
tabHost.addTab(tabSpec4, DummyFragment.class, bundle4);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}



import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class DummyFragment extends Fragment {
private TextView text_dummyfragment;
private Bundle bundle = null;
private int tabIndex = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bundle = getArguments();
tabIndex = bundle.getInt("tabIndex");
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_dummy, container, false);
text_dummyfragment = (TextView) view
.findViewById(R.id.text_dummyfragment);

Log.i("", "==" + tabIndex);

switch (tabIndex) {
case 1:
text_dummyfragment.setText("这个是记录页面");
break;
case 2:
text_dummyfragment.setText("这个是联系人页面");
break;
case 3:
text_dummyfragment.setText("这个是收藏夹页面");
break;
case 4:
text_dummyfragment.setText("这个是群组页面");
break;
default:
break;
}
return view;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值