RadioButton界面显隐
来源:互联网 发布:dede 修改服务器域名 编辑:程序博客网 时间:2024/05/18 03:38
package com.example.administrator.lovegift;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTransaction;import android.widget.RadioGroup;import com.example.administrator.lovegift.fragment.CategoryFragment;import com.example.administrator.lovegift.fragment.GuideFragment;import com.example.administrator.lovegift.fragment.HortFragment;import com.example.administrator.lovegift.fragment.MainFragment;import java.lang.reflect.InvocationTargetException;public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener { private RadioGroup mRadioGroup; private Fragment mCashFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup); mRadioGroup.setOnCheckedChangeListener(this); //首先默认加载第一个GuideFragment FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mCashFragment = new GuideFragment(); ft.add(R.id.container_activity_main, mCashFragment, GuideFragment.TAG); ft.commit(); } /*********************** * RadioGroup.OnCheckedChangeListener的回调 ******************************/ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.controller_guide: switchPage(GuideFragment.TAG, GuideFragment.class); break; case R.id.controller_hort: switchPage(HortFragment.TAG, HortFragment.class); break; case R.id.controller_category: switchPage(CategoryFragment.TAG, CategoryFragment.class); break; case R.id.controller_main: switchPage(MainFragment.TAG, MainFragment.class); break; } } //切换Fragment 的方法 private void switchPage(String TAG, Class<? extends Fragment> cls) { FragmentManager fm = getSupportFragmentManager(); FragmentTransaction tr = fm.beginTransaction(); //隐藏当前显示的页面 if (mCashFragment != null) { tr.hide(mCashFragment); } //去FragmentManager栈中查找将要显示的页面是否存在 mCashFragment = fm.findFragmentByTag(TAG); if (mCashFragment != null) { //显示页面 tr.show(mCashFragment); } else { try { mCashFragment = cls.getConstructor().newInstance(); tr.add(R.id.container_activity_main, mCashFragment, TAG); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } //提交 tr.commit(); }}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.administrator.mygift.MainActivity"> <FrameLayout android:id="@+id/container_activity_main" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> <include layout="@layout/activity_controller"/></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="@dimen/activity_controller_height" android:background="#F5F5F5" > <RadioGroup android:id="@+id/radioGroup" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:gravity="center" > <RadioButton android:id="@+id/controller_guide" style="@style/below_activity" android:text="指南" android:drawableTop="@drawable/guide" android:checked="true" /> <RadioButton android:id="@+id/controller_hort" style="@style/below_activity" android:text="热门" android:drawableTop="@drawable/hort" /> <RadioButton android:id="@+id/controller_category" style="@style/below_activity" android:text="分类" android:drawableTop="@drawable/category" /> <RadioButton android:id="@+id/controller_main" style="@style/below_activity" android:text="我的" android:drawableTop="@drawable/main" /> </RadioGroup></LinearLayout>
0 0
- RadioButton界面显隐
- Android界面组件2---RadioButton、CheckBox
- 13-界面控件之RadioButton和CheckBox
- Viewpaper Fragment RadioButton 仿QQ主界面
- RadioButton的selector以及切换界面
- radiobutton
- radioButton
- Radiobutton
- RadioButton
- RadioButton
- RadioButton
- radiobutton
- RadioButton
- RadioButton
- RadioButton
- Radiobutton
- RadioButton
- RadioButton
- 线性表之顺序存储
- 回调函数(callback)是什么?
- 怎么在浏览器网站前添加图标(图片)
- TextWatcher参数理解
- activiti 数据库核心关系表
- RadioButton界面显隐
- BAT三家的CDN情况究竟如何
- UVA.10986 Fractions Again (经典暴力)
- 18. 4Sum 题解
- Android之JSON的三种解析方式
- 多线程的三种方式
- C++函数之函数与数组
- python——高阶函数——map reduce filter sorted
- Android开源项目LifeUtil 之数据展示