package top.iletter.lvnote; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; public class FragmentProfile extends Fragment { public FragmentProfile() { // Required empty public constructor } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_profile, container, false); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // 安全地操作 View TextView movieCount = view.findViewById(R.id.tv_movie_count); TextView bookCount = view.findViewById(R.id.tv_book_count); if (movieCount != null) movieCount.setText("14"); if (bookCount != null) bookCount.setText("18"); } }