`
huiji232
  • 浏览: 11953 次
社区版块
存档分类
最新评论

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;
	}
}
分享到:
评论

相关推荐

    FragmentTabHost+fragment+viewpager listview跟新

    FragmentTabHost+fragment+viewpager为主体框架,登陆为模仿QQ登陆(可以记录每次登陆账号&lt;使用sqlite&gt;+popwindows),含有popWindow封装的弹出选择按钮。有较为复杂的xml界面。优酷跑马灯效果,上拉刷新,下拉加载...

    FragmentTabHost(仿QQ界面)

    在仿QQ界面的设计中,`FragmentTabHost`通常会用到多个自定义的`Fragment`,每个`Fragment`负责显示不同类别的信息,如聊天记录、联系人列表、个人资料等。通过动态加载和管理这些`Fragment`,可以实现类似QQ那样...

    使用RadioGroup 实现FragmentTabhost效果

    记录:对RadioGroup设置图片的几种方式,使用drawableTop设置值和background,推荐使用Drawable方式 ,使用该方式还可以控制文字,将所有的tab内容设置为background 影响效果。但是不管是哪种方式,在不同手机屏上的...

    (源码)基于Android的校园卡管理系统.zip

    5. 多Fragment管理通过自定义的FragmentTabHost和PagerAdapter,实现多个Fragment的管理和切换。 ## 安装使用步骤 2. 导入项目使用Android Studio打开下载的项目文件。 3. 配置环境确保本地环境已安装Java开发工具...

    安卓FragmentTab选项卡相关-Android高仿华为Tab页的滑动导航功能.rar

    7. **事件监听与处理**: 在TabLayout和ViewPager的交互中,可能需要设置监听器,例如OnPageChangeListener,来处理页面切换时的逻辑,比如更新顶部栏的状态、记录用户的行为等。 8. **资源文件和布局设计**: 除了...

    Android Fragment应用实战Demo,向ActivityGroup说再见 源码程序

    然而,由于Fragment的出现,现在推荐使用FragmentTabHost和FragmentTransaction来实现相同的功能,这种方式更符合现代Android开发的最佳实践,且兼容性更强。 8. **Back Stack管理**:FragmentTransaction还支持...

Global site tag (gtag.js) - Google Analytics