You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.1 KiB

package com.example.test1.fragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.SearchView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.test1.Product;
import com.example.test1.ProductAdapter;
import com.example.test1.R;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class IndexFragment extends Fragment implements View.OnClickListener {
private SearchView searchView;
private LinearLayout orangeLine, youziLine, juziLine, xiguaLine, liLine, appleLine, lemonLine, mangguoLine;
private GridView gridView;
private List productList;
private ProductAdapter productAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index, container, false);
init(view);
return view;
}
/**
* 初始化组件
*/
private void init(View view) {
searchView = view.findViewById(R.id.searchView);
searchView.setOnClickListener(this);
orangeLine = view.findViewById(R.id.chengzi);
orangeLine.setOnClickListener(this);
youziLine = view.findViewById(R.id.youzi);
youziLine.setOnClickListener(this);
juziLine = view.findViewById(R.id.juzi);
juziLine.setOnClickListener(this);
xiguaLine = view.findViewById(R.id.xigua);
xiguaLine.setOnClickListener(this);
liLine = view.findViewById(R.id.li);
liLine.setOnClickListener(this);
lemonLine = view.findViewById(R.id.lemon);
lemonLine.setOnClickListener(this);
mangguoLine = view.findViewById(R.id.mangguo);
mangguoLine.setOnClickListener(this);
appleLine = view.findViewById(R.id.apple);
appleLine.setOnClickListener(this);
gridView = view.findViewById(R.id.index_famous_gridview);
initData();
productAdapter = new ProductAdapter(getActivity(), productList);
gridView.setAdapter(productAdapter);
}
@Override
public void onClick(View v) {
}
/**
* 初始化商品数据
*/
private void initData() {
productList = new ArrayList<>();
Product product = new Product();
product.setImageUrlId(R.drawable.suanxiang);
product.setProductName("蒜香");
product.setProductPrice(new BigDecimal("2999.00"));
Product product1 = new Product();
product1.setImageUrlId(R.drawable.xiuxiu);
product1.setProductName("咻咻");
product1.setProductPrice(new BigDecimal("2999.00"));
Product product2 = new Product();
product2.setImageUrlId(R.drawable.mommy);
product2.setProductName("mommy");
product2.setProductPrice(new BigDecimal("1999.00"));
Product product3 = new Product();
product3.setImageUrlId(R.drawable.chanjie);
product3.setProductName("蝉姐");
product3.setProductPrice(new BigDecimal("1999.00"));
Product product4 = new Product();
product4.setImageUrlId(R.drawable.yuanbao);
product4.setProductName("元宝");
product4.setProductPrice(new BigDecimal("9999.00"));
Product product5 = new Product();
product5.setImageUrlId(R.drawable.furong);
product5.setProductName("芙蓉");
product5.setProductPrice(new BigDecimal("9999.00"));
productList.add(product);
productList.add(product1);
productList.add(product2);
productList.add(product3);
productList.add(product4);
productList.add(product5);
}
}