分类

public class fenlei_Fragment extends Fragment implements IFenleiView,IShouyeView{

    private ListView shouye_listview;
    private FrameLayout shouye_frame;
    private FenleiPresenter fenleiPresenter;
    private ImageView fenlei_image;
    private ShouyelistViewPresenter shouyelistViewPresenter;
    private GridView fenlei_gridview;
    private List<ShouyeBean.DataBean.ListBean > list3=new ArrayList<>();
    private ImageView sao;
    private EditText shuru_text;
    private static final int REQUEST_CODE = 1001;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fenlei_fragment, container, false);

        shouye_listview = (ListView) view.findViewById(R.id.shouye_listview);
        shouye_frame = (FrameLayout) view.findViewById(R.id.shouye_frame);
        fenlei_image = (ImageView) view.findViewById(R.id.fenlei_image);
        fenlei_gridview = (GridView) view.findViewById(R.id.fenlei_gridview);
        sao = (ImageView) view.findViewById(R.id.sao);
        //点机扫描进入二维码
        sao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), ErweimaActivity.class);
                startActivityForResult(intent, REQUEST_CODE);

            }
        });

        shuru_text = (EditText) view.findViewById(R.id.shuru_text);
        //搜索框
        shuru_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), SousuoActivity.class);
                startActivity(intent);
            }
        });



        fenleiPresenter = new FenleiPresenter(this);
        fenleiPresenter.getFenlei("https://www.zhaoapi.cn/product/getCatagory");





        shouyelistViewPresenter = new ShouyelistViewPresenter(this);


        return view;
    }

    @Override
    public void onCartSuccess(final GoodsFenleiBean goodsFenleiBean) {
           getActivity().runOnUiThread(new Runnable() {
               @Override
               public void run() {
                   final List<GoodsFenleiBean.DataBean> data = goodsFenleiBean.getData();
                   FenleiAdapter fenleiAdapter=new FenleiAdapter(data,getActivity());
                   shouye_listview.setAdapter(fenleiAdapter);
                   //点击条目
                   shouye_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {



                       @Override
                       public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                           int cid = data.get(position).getCid();
                           shouyelistViewPresenter.getShouye("https://www.zhaoapi.cn/product/getProductCatagory",cid);
                           Glide.with(getActivity()).load(data.get(position).getIcon()).into(fenlei_image);
                       }
                   });

               }
           });

    }

    @Override
    public void postShouye(final ShouyeBean shouyeBean) {

        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(list3.size()!=0){
                    list3.removeAll(list3);
                    final List<ShouyeBean.DataBean> list = shouyeBean.getData();

                    for (int i = 0; i <shouyeBean.getData().size() ; i++) {
                        for (int j = 0; j < shouyeBean.getData().get(i).getList().size(); j++) {
                            ShouyeBean.DataBean.ListBean listBean = shouyeBean.getData().get(i).getList().get(j);
                            list3.add(listBean);


                        }
                        fenlei_gridview.setAdapter(new BaseAdapter() {
                            @Override
                            public int getCount() {
                                return list3.size();
                            }

                            @Override
                            public Object getItem(int position) {
                                return list3.get(position);
                            }

                            @Override
                            public long getItemId(int position) {
                                return position;
                            }

                            @Override
                            public View getView(int position, View convertView, ViewGroup parent) {
                                View view = View.inflate(getActivity(), R.layout.fenlei_gridview, null);
                                TextView fenlei_text = (TextView) view.findViewById(R.id.fenlei_gridview_text);
                                ImageView imageView=(ImageView) view.findViewById(R.id.fenlei_gridview_image);
                                fenlei_text.setText(list3.get(position).getName());
                                Glide.with(getActivity()).load(list3.get(position).getIcon()).into(imageView);
                                return view;
                            }
                        });
                    }
                }else{
                    final List<ShouyeBean.DataBean> list = shouyeBean.getData();

                    for (int i = 0; i <shouyeBean.getData().size() ; i++) {
                        for (int j = 0; j < shouyeBean.getData().get(i).getList().size(); j++) {
                            ShouyeBean.DataBean.ListBean listBean = shouyeBean.getData().get(i).getList().get(j);
                            list3.add(listBean);


                        }
                        fenlei_gridview.setAdapter(new BaseAdapter() {
                            @Override
                            public int getCount() {
                                return list3.size();
                            }

                            @Override
                            public Object getItem(int position) {
                                return list3.get(position);
                            }

                            @Override
                            public long getItemId(int position) {
                                return position;
                            }

                            @Override
                            public View getView(int position, View convertView, ViewGroup parent) {
                                View view = View.inflate(getActivity(), R.layout.fenlei_gridview, null);
                                TextView fenlei_text = (TextView) view.findViewById(R.id.fenlei_gridview_text);
                                ImageView imageView=(ImageView) view.findViewById(R.id.fenlei_gridview_image);
                                fenlei_text.setText(list3.get(position).getName());
                                Glide.with(getActivity()).load(list3.get(position).getIcon()).into(imageView);
                                return view;
                            }

                        });

                    }
                }

            }
        });
        fenlei_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getActivity(),"点击了",Toast.LENGTH_SHORT).show();
                 Intent intent = new Intent(getActivity(), SousuoZhanshiActivity.class);
                 intent.putExtra("sousuo",list3.get(position).getName());
                startActivity(intent);
            }
        });

    }
    //二维码吐司
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == REQUEST_CODE) {
            //处理扫描结果(在界面上显示)
            if (null != data) {
                //拿到传递回来的数据
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }

                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                    //解析得到的结果
                    String result = bundle.getString(CodeUtils.RESULT_STRING);
                    Toast.makeText(getActivity(), "解析结果:" + result, Toast.LENGTH_LONG).show();
                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                    Toast.makeText(getActivity(), "解析二维码失败", Toast.LENGTH_LONG).show();
                }
            }
        }

    }
}
 
 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="50dp"
      android:orientation="horizontal"

      >
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:id="@+id/sao"
        android:layout_weight="1"
        android:padding="5dp"
        android:background="@drawable/sao_kind"
        />
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="8"
        android:orientation="horizontal"

        >
      <ImageView
          android:layout_width="20dp"
          android:layout_height="20dp"
          android:background="@drawable/search_icon2"
          android:layout_gravity="center_vertical"
          android:padding="10dp"
          />
      <EditText
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="8"
          android:hint="请输入商品名"
          android:focusable="false"
          android:id="@+id/shuru_text"
          />
    </LinearLayout>
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/order_msg"
        android:padding="10dp"
        />
  </LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >

  <ListView
      android:layout_width="0dp"
      android:layout_height="match_parent"
      android:layout_weight="2"
      android:id="@+id/shouye_listview"
      ></ListView>

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="8"
        android:id="@+id/shouye_frame"
        >
      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          >
      <ImageView
          android:layout_width="match_parent"
          android:layout_height="300dp"
          android:id="@+id/fenlei_image"
          />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="专场推荐↓"
            android:textSize="20dp"
            />
        <GridView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="2"
            android:id="@+id/fenlei_gridview"
            ></GridView>

      </LinearLayout>
      
    </FrameLayout>
</LinearLayout>

</LinearLayout>


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值