国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

商品左右分類

2019-11-08 00:28:32
字體:
供稿:網(wǎng)友
package com.example.shangcheng.fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.AbsListView;import com.avos.avoscloud.AVException;import com.avos.avoscloud.AVFile;import com.avos.avoscloud.AVObject;import com.avos.avoscloud.AVQuery;import com.avos.avoscloud.FindCallback;import com.chad.library.adapter.base.BaseQuickAdapter;import com.chad.library.adapter.base.listener.OnItemClickListener;import com.example.shangcheng.R;import com.example.shangcheng.adapter.LiftAdapter;import com.example.shangcheng.adapter.RightAdapter;import com.example.shangcheng.bean.FoodBean;import com.example.shangcheng.bean.FoodIndexBean;import java.util.ArrayList;import java.util.List;import de.halfbit.pinnedsection.PinnedSectionListView;/** * Created by Hello on 2017/2/14. */public class GoodsFragment extends Fragment { PRivate List<FoodBean> mFoodBeanList = new ArrayList<>(); private ArrayList<FoodIndexBean> mLeftRecData = new ArrayList<>(); private RecyclerView mRecyclerview; private PinnedSectionListView mRightListview; private RightAdapter mRightAdapter; private LiftAdapter mLeftAdapter; private int mFirstVisibleItem; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = View.inflate(getActivity(), R.layout.goods_fragment_layout, null); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initView(); Bundle bundle = getArguments(); String id = bundle.getString("id"); AVQuery<AVObject> query = new AVQuery<>("Product_category"); AVObject store = AVObject.createWithoutData("Store", id); query.whereEqualTo("store", store); query.include("products"); query.findInBackground(new FindCallback<AVObject>() { @Override public void done(List<AVObject> list, AVException e) { for (AVObject a : list ) { List<AVObject> products = (List<AVObject>) a.get("products"); FoodIndexBean foodIndexBean = new FoodIndexBean(); String name = (String) a.get("name"); foodIndexBean.indexName = name; mLeftRecData.add(foodIndexBean); for (AVObject avObject : products) { FoodBean foodBean = new FoodBean(); foodBean.foodSort = avObject.getString("category_name"); foodBean.foodName = avObject.getString("name"); String price = avObject.getString("price"); AVFile image = (AVFile) avObject.get("image"); foodBean.img = image; foodBean.foodPrice = price; mFoodBeanList.add(foodBean); } } refreshUI(mFoodBeanList, mLeftRecData); } ///////////////////////////////////////////// }); } private void initView() { mRecyclerview = (RecyclerView) getView().findViewById(R.id.left_recyview); mRightListview = (PinnedSectionListView) getView().findViewById(R.id.right_listview); mRightAdapter = new RightAdapter(getActivity(), mFoodBeanList); mLeftAdapter = new LiftAdapter(mLeftRecData); mRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity())); mRecyclerview.setAdapter(mLeftAdapter); mRightListview.setAdapter(mRightAdapter); mRecyclerview.addOnItemTouchListener(new OnItemClickListener() { @Override public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) { FoodIndexBean item = mLeftAdapter.getItem(position); mRightListview.setSelection(item.index); changeLeftRecSelect(item); } }); mRightListview.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (mFoodBeanList == null || mFoodBeanList.size() == 0) return; if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { // LogUtils.d("符合滑動選中條件,第一個可見條目:" + mFirstVisibleItem); FoodBean foodBean = mFoodBeanList.get(mFirstVisibleItem); FoodIndexBean foodIndexBean = new FoodIndexBean(); foodIndexBean.indexName = foodBean.foodSort; changeLeftRecSelect(foodIndexBean); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { mFirstVisibleItem = firstVisibleItem; } }); } private void refreshUI(List<FoodBean> mFoodBeanList, List<FoodIndexBean> mLeftRecData) { for (int i = 0; i < mLeftRecData.size(); i++) { FoodIndexBean foodIndexBean = mLeftRecData.get(i); foodIndexBean.index = i; } for (int i = 0; i < mLeftRecData.size(); i++ ) { FoodIndexBean f = mLeftRecData.get(i); FoodBean foodBean = new FoodBean(); foodBean.pin = f.indexName; foodBean.foodSort = f.indexName; for (int j = 0; j < mFoodBeanList.size(); j++) { FoodBean foodBean1 = mFoodBeanList.get(j); if (foodBean1.foodSort.equals(foodBean.foodSort)) { mFoodBeanList.add(j, foodBean); break; } } } mLeftAdapter.notifyDataSetChanged(); mRightAdapter.notifyDataSetChanged(); } private void changeLeftRecSelect(FoodIndexBean bean) { for (FoodIndexBean bookIndexBean : mLeftRecData) { bookIndexBean.isSelected = bookIndexBean.equals(bean); } mLeftAdapter.notifyDataSetChanged(); }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 托克逊县| 惠东县| 施甸县| 梁山县| 叙永县| 交城县| 新建县| 枝江市| 水富县| 彰化县| 读书| 泾源县| 莫力| 靖西县| 大关县| 常熟市| 资阳市| 恩平市| 仁布县| 鲁山县| 河北区| 南城县| 福贡县| 溧阳市| 长岭县| 平南县| 三原县| 永城市| 光山县| 聊城市| 綦江县| 阿坝县| 枣强县| 和田市| 友谊县| 正安县| 永德县| 晋宁县| 屏边| 屏边| 福泉市|