阶段一冲刺八
昨天任务
将自己的项目代码与队伍其他成员代码进行整合
今天任务
开始学习底部导航栏的制作
学习fragment
<?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=".FragmentActivity" android:orientation="vertical"> <fragment android:id="@+id/fragment" android:layout_width="match_parent" android:layout_height="wrap_content" tools:layout="@layout/fragment_static" android:name="com.example.belowmeue.fragment.StaticFragment"/> </LinearLayout>
package com.example.belowmeue.fragment;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;
import com.example.belowmeue.R;
/**
* A simple {@link Fragment} subclass.
* Use the {@link DongtaiFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class DongtaiFragment extends Fragment {
private TextView textview;
private RadioButton radio_like,radio_dislike;
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public DongtaiFragment() {
}
public static DongtaiFragment newInstance(String param1, String param2) {
DongtaiFragment fragment = new DongtaiFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dongtai, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
textview = view.findViewById(R.id.textview);
radio_like = view.findViewById(R.id.ridio_like);
radio_dislike = view.findViewById(R.id.ridio_dislike);
radio_like.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(b){
textview.setText("APP喜欢");
}
}
});
radio_dislike.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
textview.setText("APP不喜欢");
}
}
});
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}