RadioButton加Fragment,点击按钮替换布局,注册Fragment
来源:互联网 发布:cf驱动辅助源码 编辑:程序博客网 时间:2024/06/06 16:25
activity_main的布局
<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" > <!--将被替换的布局--> <RelativeLayout android:id="@+id/rela" android:layout_weight="6" android:layout_width="match_parent" android:layout_height="0dp"> </RelativeLayout> <RadioGroup android:id="@+id/radio_group" android:background="#fddfdd" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:checked="true" android:id="@+id/btn_zhuce" android:gravity="center" android:padding="20dp" android:textSize="23sp" android:button="@null" android:text="注册" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/btn_denglu" android:gravity="center" android:padding="20dp" android:textSize="23sp" android:button="@null" android:text="登录" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" /> </RadioGroup></LinearLayout>
Mainactivity的代码。获取id。替换布局
public class MainActivity extends AppCompatActivity { private RelativeLayout relativeLayout; private RadioGroup radioGroup; // private FragmentTransaction transaction; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //用fragment替换的布局 relativeLayout = (RelativeLayout) findViewById(R.id.rela); radioGroup = (RadioGroup) findViewById(R.id.radio_group); //进入页面先展示 注册页面 getSupportFragmentManager().beginTransaction().replace(R.id.rela,new ZhuceFragment()).commit(); // transaction = getSupportFragmentManager().beginTransaction(); //按钮选中的监听 radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i){ case R.id.btn_zhuce: getSupportFragmentManager().beginTransaction().replace(R.id.rela,new ZhuceFragment()).commit(); break; case R.id.btn_denglu: getSupportFragmentManager().beginTransaction().replace(R.id.rela,new DengluFragment()).commit(); break; } //执行替换 // transaction.commit(); } }); }}
ZhuceFragment里面
public class ZhuceFragment extends Fragment { private EditText zhu_phone; private EditText zhu_password; private Button zhuce; private MyPresenter myPresenter; //注册页面 @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //填充布局 View view = inflater.inflate(R.layout.fragment_zhuce,container,false); zhu_phone = (EditText) view.findViewById(R.id.zhu_phone); zhu_password = (EditText) view.findViewById(R.id.zhu_password); zhuce = (Button) view.findViewById(R.id.zhuce); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //new出presenter对象 myPresenter = new MyPresenter(getActivity(), new MyPresenter.ZhuceViewCallBack() { @Override public void zhu_phone_empty() { Toast.makeText(getActivity(), "注册手机号不能为空", Toast.LENGTH_SHORT).show(); } @Override public void zhu_pass_empty() { Toast.makeText(getActivity(),"注册密码不能为空",Toast.LENGTH_SHORT).show(); } @Override public void zhu_success() { Toast.makeText(getActivity(),"注册成功!请前往登录页面!",Toast.LENGTH_SHORT).show(); } @Override public void zhu_fail() { Toast.makeText(getActivity(),"不存在!",Toast.LENGTH_SHORT).show(); } }, new MyPresenter.LoginViewCallBack() { @Override public void deng_phone_empty() { } @Override public void deng_pass_empty() { } @Override public void deng_success() { } @Override public void deng_fail() { } }); //点击注册按钮 调用p层去逻辑判断非空 zhuce.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //p层逻辑判断 myPresenter.Zhuce_Panduan(zhu_phone.getText().toString(),zhu_password.getText().toString()); } }); }}
阅读全文
0 0
- RadioButton加Fragment,点击按钮替换布局,注册Fragment
- 点击按钮更换布局中的Fragment
- BottomTabBar替换RadioButton切换Fragment
- Fragment+RadioButton点击切换页面
- Viewpager+RadioButton+fragment页面布局
- Fragment加RadioGroup布局
- android 点击按钮切换不同的fragment布局
- Fragment实现点击替换翻页
- Fragment切换。radiobutton加fragment切换(附件源码下载)
- 底部按钮RadioButton、RadioGroup和Fragment
- Fragment+RadioButton实现点击切换页面效果
- Fragment+RadioButton实现点击切换页面效果
- RadioButton+Fragment实现简单主页面布局
- 点击Back按钮删除Fragment
- Fragment点击按钮替换界面防止重新实例化,使用hide和add
- [Android]Fragment的应用/点击替换fragment应用实例
- fragment中有高德地图,点击按钮切换fragment,出现黑屏闪过。
- Andorid类似Fragment替换布局方法
- 创建节点
- 1099 及set 的使用
- Github上html页面(包括CSS样式和JS效果)如何显示出来
- OC学习篇之---第一个程序HelloWorld
- HDOJ 士兵队列训练问题 JAVA 1276
- RadioButton加Fragment,点击按钮替换布局,注册Fragment
- AGC:D
- C语音基础与提高1
- IDEA第一次配置web项目报错Cannot resolve symbol 'servlet' 配置tomcat
- python 爬虫练习二, 爬取python标准库为pdf
- mysql mysqldump只导出表结构或只导出数据的实现方法
- 5.5判断是否是闰年
- Jfinal学习日志第三章_Controller(详细图解)
- EventBus