在线直播系统源码,Android页面跳转,intent
在线直播系统源码,Android页面跳转,intent
activity_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity"
android:orientation="vertical">
<TextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="2"/>
<Button
android:onClick="back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="返回"/>
</LinearLayout>
MainActivity.java
package cn.itcast.zuoye;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
TextView textView;
EditText uname;
EditText psw;
RadioGroup sex;
String sexcheck;
String hobbys;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("activtiy=========>onCreate");
uname = findViewById(R.id.uname);
psw = findViewById(R.id.psw);
sex =findViewById(R.id.sex);
//初始化CheckBox控件
CheckBox like1 = findViewById(R.id.like1);
CheckBox like2 = findViewById(R.id.like2);
CheckBox like3 = findViewById(R.id.like3);
like1.setOnCheckedChangeListener(this);
like2.setOnCheckedChangeListener(this);
like3.setOnCheckedChangeListener(this);
hobbys = new String();//存放选中的Checkbox的文本
//给性别单选框设置监听事件判断选择的性别
sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
if(checkedId == R.id.woman){
sexcheck = "女";
} else {
sexcheck = "男";
}
}
});
}
@Override
protected void onStart() {
System.out.println("activtiy=========>onStart");
super.onStart();
}
@Override
protected void onResume() {
System.out.println("activtiy=========>onResume获取焦点时候调用");
super.onResume();
}
@Override
protected void onPause() {
System.out.println("activtiy=========>onPause失去焦点时候调用,也就是离开软件时调用");
super.onPause();
}
@Override
protected void onStop() {
System.out.println("activtiy=========>onStop");
super.onStop();
}
@Override
protected void onRestart() {
System.out.println("activtiy=========>onRestart");
super.onRestart();
}
@Override
protected void onDestroy() {
System.out.println("activtiy=========>onDestroy,停用软件时调用");
super.onDestroy();
}
//显示调用
public void toActivity(View view){
String userName = uname.getText().toString();
Intent intent = new Intent();//声明意图
intent.putExtra("userName",userName);//把值放在了intent里面
User user = new User();
user.setUserName(userName);
intent.putExtra("user",user);
intent.setClass(MainActivity.this,SecondActivity.class);//从什么地方跳转到那里去
startActivity(intent);//启动意图
}
//隐式调用
public void toActivity2(View view){
Intent intent = new Intent();
intent.setAction("cn.itcast.zuoye");
String userName = uname.getText().toString();
String passWord = psw.getText().toString();
// intent.putExtra("传递数据的名称","传递的数据信息");
intent.putExtra("userName",userName);//把值放在了intent里面
intent.putExtra("passWord",passWord);
intent.putExtra("sex",sexcheck);
intent.putExtra("hobbys",hobbys);
startActivityForResult(intent,1);
System.out.println("调用了隐式");
}
//确认多选框选中的内容参见书本59页
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {//第一个参数:被点击的控件 第二个参数:选中状态
String motion = compoundButton.getText().toString();
if(isChecked){
if(!hobbys.contains(motion)){
hobbys = hobbys + motion;
}else {
if(hobbys.contains(motion)){
hobbys = hobbys.replace(motion, "");
}
}
}
}
}
以上就是在线直播系统源码,Android页面跳转,intent, 更多内容欢迎关注之后的文章