@ -1,21 +1,102 @@
|
|||||||
package com.example.register.fragment;
|
package com.example.register.fragment;
|
||||||
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.GridView;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.example.register.R;
|
import com.example.register.R;
|
||||||
|
import com.example.register.adapter.ListViewAdapter;
|
||||||
|
import com.example.register.adapter.ProductAdapter;
|
||||||
|
import com.example.register.entity.Condition;
|
||||||
|
import com.example.register.entity.OrangeProductPack;
|
||||||
|
import com.example.register.netrequest.OkHttpClientProduct;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ProductFragment extends Fragment {
|
public class ProductFragment extends Fragment {
|
||||||
|
private Spinner conditonListSpinner;
|
||||||
|
private ListViewAdapter listViewAdapter;
|
||||||
|
private List<Condition> conditionList;
|
||||||
|
private GridView productGridView;
|
||||||
|
private List<OrangeProductPack> orangeProductList = new ArrayList<>();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false);
|
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false);
|
||||||
|
init(view);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组件初始化方法
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
*/
|
||||||
|
private void init(View view) {
|
||||||
|
conditonListSpinner = view.findViewById(R.id.product_select_condition);
|
||||||
|
initCondList();
|
||||||
|
listViewAdapter = new ListViewAdapter(getActivity(), conditionList);
|
||||||
|
conditonListSpinner.setAdapter(listViewAdapter);
|
||||||
|
productGridView = view.findViewById(R.id.product_list);
|
||||||
|
new SearchProductTask().execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化conditionList
|
||||||
|
*/
|
||||||
|
private void initCondList() {
|
||||||
|
conditionList = new ArrayList<>();
|
||||||
|
Condition allCondition = new Condition();
|
||||||
|
allCondition.setConditionIcon(R.drawable.all);
|
||||||
|
allCondition.setConditionName("全部");
|
||||||
|
Condition saleCondition = new Condition();
|
||||||
|
saleCondition.setConditionIcon(R.drawable.salenum);
|
||||||
|
saleCondition.setConditionName("按销量高低排序");
|
||||||
|
Condition timeCondition = new Condition();
|
||||||
|
timeCondition.setConditionIcon(R.drawable.time);
|
||||||
|
timeCondition.setConditionName("按上市时间排序");
|
||||||
|
Condition priceCondition = new Condition();
|
||||||
|
priceCondition.setConditionIcon(R.drawable.price);
|
||||||
|
priceCondition.setConditionName("按商品价格排序");
|
||||||
|
conditionList.add(allCondition);
|
||||||
|
conditionList.add(saleCondition);
|
||||||
|
conditionList.add(timeCondition);
|
||||||
|
conditionList.add(priceCondition);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送网络请求获取数据
|
||||||
|
*/
|
||||||
|
class SearchProductTask extends AsyncTask<Void, Void, List<OrangeProductPack>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<OrangeProductPack> doInBackground(Void... voids) {
|
||||||
|
OkHttpClientProduct clientProduct = new OkHttpClientProduct();
|
||||||
|
try {
|
||||||
|
orangeProductList = clientProduct.getProductPack();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return orangeProductList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(List<OrangeProductPack> orangeProducts) {
|
||||||
|
ProductAdapter productAdapter = new ProductAdapter(getActivity(), orangeProductList);
|
||||||
|
productGridView.setAdapter(productAdapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 5.4 KiB |
After Width: | Height: | Size: 790 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 402 B |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 554 B |
After Width: | Height: | Size: 1.1 KiB |
@ -1,11 +1,27 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical" android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include layout="@layout/content_product_title" />
|
||||||
|
|
||||||
<TextView
|
<Spinner
|
||||||
android:id="@+id/textView"
|
android:id="@+id/product_select_condition"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:paddingHorizontal="1dp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<GridView
|
||||||
|
android:id="@+id/product_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="product" />
|
android:layout_marginTop="10dp"
|
||||||
|
android:background="#E8E8E8"
|
||||||
|
android:horizontalSpacing="10dp"
|
||||||
|
android:verticalSpacing="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:numColumns="2"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|