package com.example.airmonitor.ui.mine; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import com.example.airmonitor.R; public class MineFragment extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_mine, container, false); return view; } //视图控件请在这里实例化 //活动创建之后才能对fragment中的控件进行实例化,对控件的实例化、对控件的操作要在这个活动中完成 @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); RelativeLayout mine1 = getActivity().findViewById(R.id.mine1); mine1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i=new Intent(getActivity(), Mine_About_Activity.class); startActivity(i); } }); } }