| | |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.ImageView; |
| | | 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 androidx.recyclerview.widget.GridLayoutManager; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import com.duqing.missions.R; |
| | | import com.duqing.missions.databinding.FragmentHomeBinding; |
| | | |
| | | public class HomeFragment extends Fragment { |
| | | |
| | | private HomeViewModel homeViewModel; |
| | | private FragmentHomeBinding binding; |
| | | private FragmentHomeBinding binding; |
| | | |
| | | public View onCreateView(@NonNull LayoutInflater inflater, |
| | | ViewGroup container, Bundle savedInstanceState) { |
| | | homeViewModel = |
| | | new ViewModelProvider(this).get(HomeViewModel.class); |
| | | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| | | homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class); |
| | | |
| | | binding = FragmentHomeBinding.inflate(inflater, container, false); |
| | | View root = binding.getRoot(); |
| | | binding = FragmentHomeBinding.inflate(inflater, container, false); |
| | | View root = binding.getRoot(); |
| | | final TextView textView = binding.textRecommend; |
| | | final ImageView imgSearch = binding.imgSearch; |
| | | RecyclerView recyclerClassify = binding.recyclerClassify; |
| | | RecyclerView recyclerTop = binding.recyclerTop; |
| | | final RecyclerView recyclerRecommend = binding.recyclerRecommend; |
| | | recyclerRecommend.setLayoutManager(new LinearLayoutManager(getContext())); |
| | | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); |
| | | layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); |
| | | recyclerClassify.setLayoutManager(layoutManager); |
| | | recyclerTop.setLayoutManager(new GridLayoutManager(getContext(),3)); |
| | | |
| | | final TextView textView = binding.textHome; |
| | | homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { |
| | | @Override |
| | | public void onChanged(@Nullable String s) { |
| | |
| | | return root; |
| | | } |
| | | |
| | | @Override |
| | | @Override |
| | | public void onDestroyView() { |
| | | super.onDestroyView(); |
| | | binding = null; |