package com.example.fragment; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.example.adapter.CommonGridAdapter; import com.example.smartglasses.R; import com.example.smartglasses.databinding.FragmentMineBinding; import com.xuexiang.xui.adapter.simple.AdapterItem; import com.xuexiang.xui.utils.ResUtils; import com.xuexiang.xui.utils.WidgetUtils; import java.util.ArrayList; import java.util.List; public class MineFragment extends Fragment { RecyclerView recyclerHead; FragmentMineBinding binding; private CommonGridAdapter mGridAdapter; public MineFragment() { // Required empty public constructor } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment binding = FragmentMineBinding.inflate(inflater, container, false); recyclerHead = binding.recyclerHead; initTools(); return binding.getRoot(); } public void initTools(){ WidgetUtils.initGridRecyclerView(recyclerHead, 4, 0); recyclerHead.setAdapter(mGridAdapter = new CommonGridAdapter(true)); mGridAdapter.refresh(getGridItems(this.getActivity(),R.array.grid_titles_entry,R.array.grid_icons_entry)); } private static List getGridItems(Context context, int titleArrayId, int iconArrayId) { List list = new ArrayList<>(); String[] titles = ResUtils.getStringArray(titleArrayId); Drawable[] icons = ResUtils.getDrawableArray(context, iconArrayId); for (int i = 0; i < titles.length; i++) { list.add(new AdapterItem(titles[i], icons[i])); } Log.i("TAB", "getGridItems: "+list.size()); return list; } }