Android开发--fragment中Button点击切换Activity
来源:互联网 发布:淘宝收藏宝贝没反应 编辑:程序博客网 时间:2024/06/10 17:05
页面贴图:fragment_fragment1
布局文件:fragment_fragment1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:text="用户名:" android:id="@+id/name" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:hint="Name" android:id="@+id/input" android:inputType="number" /> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="New Button" android:clickable="true" android:id="@+id/button" android:layout_gravity="center_horizontal"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:hint="提示" android:id="@+id/remind" /></LinearLayout>
Java文件:Fragment1.java
package com.example.lenovo.sitp;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Fragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_fragment1,container,false);
Button btn = (Button)view.findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText in=(EditText)view.findViewById(R.id.input);
TextView out=(TextView)view.findViewById(R.id.remind);
String s=in.getText().toString();
if(s.equals("123")){
startActivity(new Intent(getActivity(),run.class));
}else{
out.setText("错误,正确为:123");
}
}
});
return view;
}
}
- Android开发--fragment中Button点击切换Activity
- Android开发,在Activity中切换不同的Fragment
- Android中Fragment点击切换与添加ViewPager滑动切换
- Android的fragment页面点击按钮切换到下一个fragment页面,由主activity控制
- Android item上的button,在activity中点击。
- Android开发中Fragment的切换
- android activity fragment状态切换
- Android -- Activity,Fragment切换动画。
- Android中点击Button
- 如何从fragment中点击一个Button跳到另一个activity
- Android开发中关于Fragment和Activity
- Android中fragment之间和Activity的传值、切换
- android中在fragment A里面点击button跳转到fragment B怎么实现?
- Android中如何在Fragment中添加点击事件切换新的Fragment
- activity响应listview中button点击事件
- Android开发中textview显示button点击次数
- Android Fragment之间的点击切换
- Android碎片Fragment的点击切换
- angularjs中的指令
- 数据库水平切分的实现原理解析——分库,分表,主从,集群,负载均衡器(转)
- Java自动生成Mvp框架目录结构
- Codeforces 768B Code For 1
- Xcode无开发者账号真机测试
- Android开发--fragment中Button点击切换Activity
- IntelliJ IDEA 创建并部署单纯的web工程(不用Maven和Gradle管理)
- POJ 3304
- Python3.6连接MySQL
- Intent传递数据与Activity启动模式singleTask的关系。
- easyui datagrid 相同列合并/编辑行后保存
- 学生选课抽签管理系统设计(二)
- 阿里云数据盘挂载遇到的一些问题总结
- 轻量级的测试工具:ContiPerf