diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/main/device/NavDeviceFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/main/device/NavDeviceFragment.java index b936bb2..88c1994 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/main/device/NavDeviceFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/main/device/NavDeviceFragment.java @@ -1,14 +1,25 @@ package cc.niushuai.project.devcontrol.ui.nav.main.device; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.GridView; +import android.widget.SimpleAdapter; import android.widget.TextView; import androidx.fragment.app.Fragment; +import androidx.gridlayout.widget.GridLayout; import androidx.lifecycle.ViewModelProvider; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding; /** @@ -19,27 +30,50 @@ import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding; */ public class NavDeviceFragment extends Fragment { - private MainNavFragmentDeviceBinding navFragmentDeviceBinding; + private MainNavFragmentDeviceBinding binding; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - navFragmentDeviceBinding = MainNavFragmentDeviceBinding.inflate(inflater, container, false); + binding = MainNavFragmentDeviceBinding.inflate(inflater, container, false); NavDeviceViewModel navDeviceViewModel = new ViewModelProvider(this).get(NavDeviceViewModel.class); - View rootView = navFragmentDeviceBinding.getRoot(); + View rootView = binding.getRoot(); // TextView textView = navFragmentDeviceBinding.navDeviceFragmentTextview; // // navDeviceViewModel.getText().observe(getViewLifecycleOwner(), textView::setText); + setDevices(); + return rootView; } + private void setDevices() { + +// GridLayout deviceGridLayout = binding.deviceGridLayout; + GridView deviceGv = binding.deviceGv; + deviceGv.setSelector(new ColorDrawable(Color.TRANSPARENT)); + + List> dataItem = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + HashMap m1 = new HashMap<>(); + + m1.put("device_item_imageView", R.drawable.ic_mark_as_read); + m1.put("device_item_textView", "卧室灯" + i); + dataItem.add(m1); + } + + SimpleAdapter gvAdapter = new SimpleAdapter(getContext(), dataItem, R.layout.device_item, + new String[]{"device_item_imageView", "device_item_textView"}, new int[]{R.id.device_item_imageView, R.id.device_item_textView}); + + deviceGv.setAdapter(gvAdapter); + } + @Override public void onDestroyView() { super.onDestroyView(); - navFragmentDeviceBinding = null; + binding = null; } } \ No newline at end of file diff --git a/app/src/main/res/layout/device_item.xml b/app/src/main/res/layout/device_item.xml new file mode 100644 index 0000000..7761cc2 --- /dev/null +++ b/app/src/main/res/layout/device_item.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main_nav_fragment_device.xml b/app/src/main/res/layout/main_nav_fragment_device.xml index cb59517..52f20f6 100644 --- a/app/src/main/res/layout/main_nav_fragment_device.xml +++ b/app/src/main/res/layout/main_nav_fragment_device.xml @@ -6,16 +6,24 @@ xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".ui.nav.main.device.NavDeviceFragment"> - + android:layout_height="match_parent"> + + + + + + + \ No newline at end of file