| | |
| | | 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; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProvider; |
| | | |
| | | import com.duqing.missions.R; |
| | | import com.duqing.missions.databinding.FragmentDashboardBinding; |
| | | |
| | | public class DashboardFragment extends Fragment { |
| | | |
| | | private DashboardViewModel dashboardViewModel; |
| | | private FragmentDashboardBinding binding; |
| | | private FragmentDashboardBinding binding; |
| | | |
| | | public View onCreateView(@NonNull LayoutInflater inflater, |
| | | ViewGroup container, Bundle savedInstanceState) { |
| | | dashboardViewModel = |
| | | new ViewModelProvider(this).get(DashboardViewModel.class); |
| | | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| | | dashboardViewModel = new ViewModelProvider(this).get(DashboardViewModel.class); |
| | | |
| | | binding = FragmentDashboardBinding.inflate(inflater, container, false); |
| | | View root = binding.getRoot(); |
| | | binding = FragmentDashboardBinding.inflate(inflater, container, false); |
| | | View root = binding.getRoot(); |
| | | |
| | | final TextView textView = binding.textDashboard; |
| | | dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { |
| | | @Override |
| | | public void onChanged(@Nullable String s) { |
| | | textView.setText(s); |
| | | } |
| | | }); |
| | | return root; |
| | | } |
| | | |
| | | @Override |
| | | @Override |
| | | public void onDestroyView() { |
| | | super.onDestroyView(); |
| | | binding = null; |