From 07ee79198d70d8cc10530cc8d09ca50aaccb62dd Mon Sep 17 00:00:00 2001 From: liu <3408670094@qq.com> Date: Mon, 24 Apr 2023 21:40:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AF=BC=E8=88=AA=E6=A0=8F?= =?UTF-8?q?=E5=8F=8A=E9=A6=96=E9=A1=B5=E5=88=B6=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .../orangesale/cn/activity/IndexActivity.java | 105 ++++++++------- .../orangesale/cn/adapter/ProductAdapter.java | 70 ++++++++++ .../orangesale/cn/fragment/IndexFragment.java | 55 +++++--- .../cn/fragment/PersonFragment.java | 1 - .../cn/fragment/ProductFragment.java | 2 +- app/src/main/res/layout/content_index.xml | 124 ++++++++++++++++++ app/src/main/res/layout/content_product.xml | 13 ++ app/src/main/res/layout/content_shopping.xml | 13 ++ app/src/main/res/layout/fragment_index.xml | 22 ++-- app/src/main/res/layout/fragment_person.xml | 14 -- app/src/main/res/layout/fragment_product.xml | 14 -- app/src/main/res/layout/fragment_shopping.xml | 14 -- app/src/main/res/layout/index_hot.xml | 55 ++++++++ 14 files changed, 379 insertions(+), 125 deletions(-) create mode 100644 app/src/main/java/com/orangesale/cn/adapter/ProductAdapter.java create mode 100644 app/src/main/res/layout/content_index.xml create mode 100644 app/src/main/res/layout/content_product.xml create mode 100644 app/src/main/res/layout/content_shopping.xml delete mode 100644 app/src/main/res/layout/fragment_person.xml delete mode 100644 app/src/main/res/layout/fragment_product.xml delete mode 100644 app/src/main/res/layout/fragment_shopping.xml create mode 100644 app/src/main/res/layout/index_hot.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 37612a4..1442212 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -69,7 +69,7 @@ - + diff --git a/app/src/main/java/com/orangesale/cn/activity/IndexActivity.java b/app/src/main/java/com/orangesale/cn/activity/IndexActivity.java index e16eb0b..e9e7baa 100644 --- a/app/src/main/java/com/orangesale/cn/activity/IndexActivity.java +++ b/app/src/main/java/com/orangesale/cn/activity/IndexActivity.java @@ -3,24 +3,38 @@ package com.orangesale.cn.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.view.ViewTreeObserver; + import android.widget.LinearLayout; import androidx.annotation.Nullable; -import androidx.fragment.app.FragmentTransaction; + import com.orangesale.cn.R; import android.view.View; + import com.orangesale.cn.fragment.IndexFragment; import com.orangesale.cn.fragment.PersonFragment; import com.orangesale.cn.fragment.ProductFragment; import com.orangesale.cn.fragment.ShoppingFragment; -public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawListener { - private IndexFragment indexFragment; + +public class IndexActivity extends Activity implements View.OnClickListener { + private ProductFragment productFragment; private ShoppingFragment shoppingFragment; + private IndexFragment indexFragment; + private PersonFragment personFragment; - private LinearLayout indexLine, productLine, shoppingLine, personLine; + private LinearLayout indexLine; + private LinearLayout productLine; + private LinearLayout shoppingLine; + private LinearLayout personLine; + + public IndexActivity(LinearLayout indexLine,LinearLayout productLine, LinearLayout shoppingLine, LinearLayout personLine) { + this.productLine = productLine; + this.personLine = personLine; + this.indexLine = indexLine; + this.shoppingLine = shoppingLine; + } @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -40,10 +54,8 @@ public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawLi indexLine = findViewById(R.id.content_cart); shoppingLine.setOnClickListener(this); - indexLine = findViewById(R.id.content_person); + indexLine = findViewById(R.id.content_pearson); productLine.setOnClickListener(this); - - } @Override @@ -62,7 +74,7 @@ public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawLi initshoppingFragment(); break; - case R.id.content_person: + case R.id.content_pearson: //注册验证方法 initpersonFragment(); break; @@ -70,51 +82,46 @@ public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawLi } - private void initIndexFragment() { - FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (indexFragment == null) { - indexFragment = new IndexFragment(); - transaction.replace(R.id.main_content, indexFragment); - transaction.commit(); + private void initpersonFragment() { + android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction(); + + if (personFragment == null) { + Intent intent = IndexActivity.this.getIntent(); + Bundle bundle = intent.getExtras(); + personFragment = new PersonFragment(); + personFragment.setArguments(bundle); } + transaction.replace(R.id.main_content, personFragment); + transaction.commit(); + } - private void initproductFragment() { - FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (productFragment == null) { - productFragment = new ProductFragment(); - } - transaction.replace(R.id.main_content, productFragment); - transaction.commit(); - } - - private void initshoppingCartFragment() { - FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (shoppingFragment == null) { - shoppingFragment = new ShoppingFragment(); - } - transaction.replace(R.id.main_content, shoppingFragment); - transaction.commit(); - } - - private void initpersonFragment() { - FragmentTransaction transaction = getFragmentManager().beginTransaction(); - - if (personFragment == null) { - Intent intent = IndexActivity.this.getIntent(); - Bundle bundle = intent.getExtras(); - personFragment = new PersonFragment(); - personFragment.setArguments(bundle); - } - transaction.replace(R.id.main_content, personFragment); - transaction.commit(); - } - - } + private void initshoppingFragment() { + android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (shoppingFragment == null) { + shoppingFragment = new ShoppingFragment(); + } + transaction.replace(R.id.main_content, shoppingFragment); + transaction.commit(); + } - @Override - public void onDraw() { + private void initproductFragment() { + android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (productFragment == null) { + productFragment = new ProductFragment(); + } + transaction.replace(R.id.main_content, productFragment); + transaction.commit(); + } + private void initIndexFragment() { + android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (indexFragment == null) { + indexFragment = new IndexFragment(); + } + transaction.replace(R.id.main_content,productFragment); + transaction.commit(); } + } diff --git a/app/src/main/java/com/orangesale/cn/adapter/ProductAdapter.java b/app/src/main/java/com/orangesale/cn/adapter/ProductAdapter.java new file mode 100644 index 0000000..9b05b92 --- /dev/null +++ b/app/src/main/java/com/orangesale/cn/adapter/ProductAdapter.java @@ -0,0 +1,70 @@ +package com.orangesale.cn.adapter; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.orangesale.cn.R; +import com.orangesale.cn.entity.Product; + +import java.util.List; + +public class ProductAdapter extends BaseAdapter { + private List productList; + private LayoutInflater layoutInflater; + + public ProductAdapter(Context context, List productList) { + this.productList = productList; + this.layoutInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return productList.size(); + } + + @Override + public Object getItem(int position) { + return productList.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + Log.i("aa", "getView: "+"aa"); + convertView = layoutInflater.inflate(R.layout.categoty_detail_content, null); + viewHolder = new ViewHolder(); + viewHolder.productImage = convertView.findViewById(R.id.category_product_image); + viewHolder.productName = convertView.findViewById(R.id.category_product_name); + viewHolder.productPrice = convertView.findViewById(R.id.category_product_price); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + Product product = productList.get(position); + Log.i("product", "getView: "+product.toString()); + if (product != null) { + viewHolder.productImage.setBackgroundResource(product.getImageUrlId()); + viewHolder.productName.setText(product.getProductName()); + viewHolder.productPrice.setText(String.valueOf(product.getProductPrice())); + } + return convertView; + } + + class ViewHolder { + ImageView productImage; + TextView productName, productPrice; + } +} + diff --git a/app/src/main/java/com/orangesale/cn/fragment/IndexFragment.java b/app/src/main/java/com/orangesale/cn/fragment/IndexFragment.java index 3931a0a..f624136 100644 --- a/app/src/main/java/com/orangesale/cn/fragment/IndexFragment.java +++ b/app/src/main/java/com/orangesale/cn/fragment/IndexFragment.java @@ -1,6 +1,5 @@ package com.orangesale.cn.fragment; -import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -8,34 +7,59 @@ 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 androidx.fragment.app.Fragment; + import com.orangesale.cn.R; -import com.orangesale.cn.adapter.Adapter; import com.orangesale.cn.entity.Product; +import com.orangesale.cn.adapter.ProductAdapter; + + import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; -public abstract class IndexFragment extends Fragment implements View.OnClickListener { - private SearchView searchView; - private LinearLayout bingtangchengLine; +public class IndexFragment extends Fragment implements View.OnClickListener { + private GridView gridView; - private Adapter adapter; + private ProductAdapter productAdapter; private List productList; + private SearchView searchView; + private LinearLayout chuchengLine, qichengLine,bingtangchengLine; + + @Nullable @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ - View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index,container,false); + 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); + + private void init(View view) { + searchView = view.findViewById(R.id.searchview); searchView.setOnClickListener(this); + + chuchengLine= view.findViewById(R.id.chucheng); + chuchengLine.setOnClickListener(this); + qichengLine = view.findViewById(R.id.qicheng); + qichengLine.setOnClickListener(this); + bingtangchengLine = view.findViewById(R.id.bingtangcheng); + bingtangchengLine.setOnClickListener(this); + gridView = view.findViewById(R.id.index_famous_gridview); initData(); - adapter = new Adapter(getActivity(),productList); - gridView.setAdapter(adapter); + productAdapter = new ProductAdapter(getActivity(), productList); + gridView.setAdapter(productAdapter); } + @Override - public void initData(){ + public void onClick(View v) { + + + } + + private void initData() { productList = new ArrayList<>(); Product product = new Product(); product.setImageUrlId(R.drawable.bingtangcheng); @@ -51,7 +75,4 @@ public abstract class IndexFragment extends Fragment implements View.OnClickList productList.add(product1); } - - - -} +} \ No newline at end of file diff --git a/app/src/main/java/com/orangesale/cn/fragment/PersonFragment.java b/app/src/main/java/com/orangesale/cn/fragment/PersonFragment.java index f4f0f72..7e9065e 100644 --- a/app/src/main/java/com/orangesale/cn/fragment/PersonFragment.java +++ b/app/src/main/java/com/orangesale/cn/fragment/PersonFragment.java @@ -67,4 +67,3 @@ public class PersonFragment extends Fragment implements View.OnClickListener { } -} \ No newline at end of file diff --git a/app/src/main/java/com/orangesale/cn/fragment/ProductFragment.java b/app/src/main/java/com/orangesale/cn/fragment/ProductFragment.java index 2b9c096..faeefea 100644 --- a/app/src/main/java/com/orangesale/cn/fragment/ProductFragment.java +++ b/app/src/main/java/com/orangesale/cn/fragment/ProductFragment.java @@ -17,7 +17,7 @@ public class ProductFragment extends Fragment { @Nullable @Override 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_category, container, false); return view; } } diff --git a/app/src/main/res/layout/content_index.xml b/app/src/main/res/layout/content_index.xml new file mode 100644 index 0000000..6bfd291 --- /dev/null +++ b/app/src/main/res/layout/content_index.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_product.xml b/app/src/main/res/layout/content_product.xml new file mode 100644 index 0000000..246d4f3 --- /dev/null +++ b/app/src/main/res/layout/content_product.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_shopping.xml b/app/src/main/res/layout/content_shopping.xml new file mode 100644 index 0000000..d9cc5f2 --- /dev/null +++ b/app/src/main/res/layout/content_shopping.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_index.xml b/app/src/main/res/layout/fragment_index.xml index 940f1f1..3a2c60d 100644 --- a/app/src/main/res/layout/fragment_index.xml +++ b/app/src/main/res/layout/fragment_index.xml @@ -1,20 +1,14 @@ - + tools:context=".fragment.IndexFragment"> - - + - + android:layout_height="match_parent" + android:text="this is Index page" /> - /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_person.xml b/app/src/main/res/layout/fragment_person.xml deleted file mode 100644 index c8b2375..0000000 --- a/app/src/main/res/layout/fragment_person.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_product.xml b/app/src/main/res/layout/fragment_product.xml deleted file mode 100644 index d1054a2..0000000 --- a/app/src/main/res/layout/fragment_product.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_shopping.xml b/app/src/main/res/layout/fragment_shopping.xml deleted file mode 100644 index 5220259..0000000 --- a/app/src/main/res/layout/fragment_shopping.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/index_hot.xml b/app/src/main/res/layout/index_hot.xml new file mode 100644 index 0000000..c340aeb --- /dev/null +++ b/app/src/main/res/layout/index_hot.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file