diff --git a/.idea/render.experimental.xml b/.idea/render.experimental.xml deleted file mode 100644 index 8ec256a..0000000 --- a/.idea/render.experimental.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index efceecf..bc295fc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + xmlns:tools="http://schemas.android.com/tools" + package="com.example.register"> + diff --git a/app/src/main/java/com/example/register/CategoryActivity.java b/app/src/main/java/com/example/register/CategoryActivity.java new file mode 100644 index 0000000..3570787 --- /dev/null +++ b/app/src/main/java/com/example/register/CategoryActivity.java @@ -0,0 +1,114 @@ +package com.example.register; + +import android.app.Activity; +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.os.Bundle; +import android.widget.ListView; + +import androidx.annotation.Nullable; + +import com.example.register.R; +import com.example.register.entity.Product; +import com.example.register.adapter.Adapter; +import com.example.register.fragment.SetDetailFragment; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + + +public class CategoryActivity extends Activity { + public OnChangeListener onchangedListener; + private List productList; + private List productCategory = new ArrayList<>(); + private ListView titleList; + private Adapter adapter; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.content_category); + initData(); + init(); + SetDetailFragment fragment = new SetDetailFragment(); + FragmentManager fragmentManager = getFragmentManager(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + transaction.replace(R.id.category_detail, fragment); + transaction.commit(); + titleList.setOnItemClickListener((parent, view, position, id) -> { + adapter.setSelectedPosition(position); + adapter.notifyDataSetInvalidated(); + if (onchangedListener != null) { + onchangedListener.changeText(productList.get(position)); + } + }); + + } + + public void setOnChangeListener(OnChangeListener onChangeListener) { + this.onchangedListener = onChangeListener; + } + + public interface OnChangeListener { + void changeText(Product product); + } + + /** + * 初始化数据 + */ + private void initData() { + productList = new ArrayList<>(); + productCategory.add("热销"); + productCategory.add("严选"); + productCategory.add("小食"); + productCategory.add("啤酒"); + productCategory.add("饮料"); + + + Product product = new Product(); + product.setImageUrlId(R.drawable.rou); + product.setProductName("肥肉饭"); + product.setProductPrice(new BigDecimal("19.9")); + + + + Product product1 = new Product(); + product1.setImageUrlId(R.drawable.haorou); + product1.setProductName("严选套餐"); + product1.setProductPrice(new BigDecimal("29.9")); + + + Product product2 = new Product(); + product2.setImageUrlId(R.drawable.xiaoshi); + product2.setProductName("小食"); + product2.setProductPrice(new BigDecimal("9.9")); + + Product product3 = new Product(); + product3.setImageUrlId(R.drawable.shui); + product3.setProductName("矿泉水"); + product3.setProductPrice(new BigDecimal("1.9")); + + + Product product4 = new Product(); + product4.setImageUrlId(R.drawable.yinliao); + product4.setProductName("雪碧"); + product4.setProductPrice(new BigDecimal("1.9")); + + + productList.add(product); + productList.add(product1); + productList.add(product2); + productList.add(product3); + productList.add(product4); + } + + /** + * 初始化组件 + */ + private void init() { + titleList = findViewById(R.id.category_title_list); + adapter = new Adapter(productCategory, CategoryActivity.this); + titleList.setAdapter(adapter); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/register/SetDetailFragment.java b/app/src/main/java/com/example/register/SetDetailFragment.java new file mode 100644 index 0000000..0d79577 --- /dev/null +++ b/app/src/main/java/com/example/register/SetDetailFragment.java @@ -0,0 +1,50 @@ +package com.example.register; + +import android.annotation.SuppressLint; +import android.app.Fragment; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.util.Objects; + +public class SetDetailFragment extends Fragment { + private View view; + private ImageView imageView; + private TextView nameText, priceText; + + @SuppressLint("SetTextI18n") + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + view = inflater.inflate(R.layout.categoty_detail_content, container, false); + if (view != null) { + init(); + } + CategoryActivity categoryActivity = (CategoryActivity) getActivity(); + Objects.requireNonNull(categoryActivity).setOnChangeListener(product -> { + Log.i("sss", "onCreateView: " + product.getProductName()); + imageView.setBackgroundResource(product.getImageUrlId()); + nameText.setText(product.getProductName()); + priceText.setText(product.getProductPrice().toString()); + }); + return view; + } + + /** + * 内容组件初始化 + */ + private void init() { + imageView = view.findViewById(R.id.category_product_image); + nameText = view.findViewById(R.id.category_product_name); + priceText = view.findViewById(R.id.category_product_price); + } + +} diff --git a/app/src/main/java/com/example/register/adapter/Adapter.java b/app/src/main/java/com/example/register/adapter/Adapter.java new file mode 100644 index 0000000..b8c7cc0 --- /dev/null +++ b/app/src/main/java/com/example/register/adapter/Adapter.java @@ -0,0 +1,69 @@ +package com.example.register.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.example.register.R; + +import java.util.List; + +public class Adapter extends BaseAdapter { + private List productCategory; + private LayoutInflater layoutInflater; + private int selectionPosition = -1; + + public Adapter(List productCategory, Context context) { + this.productCategory = productCategory; + this.layoutInflater = LayoutInflater.from(context); + } + + @Override + public int getCount() { + return productCategory.size(); + } + + @Override + public Object getItem(int position) { + return productCategory.get(position); + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder = null; + if (convertView == null) { + viewHolder = new ViewHolder(); + convertView = layoutInflater.inflate(R.layout.category_list_item, null); + Log.i("adapts", "getView: " + convertView); + viewHolder.tv = convertView.findViewById(R.id.categor_titles); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + viewHolder.tv.setText(productCategory.get(position)); + if (selectionPosition == position) { + viewHolder.tv.setBackgroundColor(Color.YELLOW); + } else { + viewHolder.tv.setBackgroundColor(Color.WHITE); + } + return convertView; + } + + public void setSelectedPosition(int position) { + this.selectionPosition = position; + } + + class ViewHolder { + TextView tv; + } +} diff --git a/app/src/main/java/com/example/register/entity/Product.java b/app/src/main/java/com/example/register/entity/Product.java new file mode 100644 index 0000000..f03fa1e --- /dev/null +++ b/app/src/main/java/com/example/register/entity/Product.java @@ -0,0 +1,34 @@ +package com.example.register.entity; + +import java.math.BigDecimal; + +public class Product { + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public BigDecimal getProductPrice() { + return productPrice; + } + + public void setProductPrice(BigDecimal productPrice) { + this.productPrice = productPrice; + } + + public Integer getImageUrlId() { + return imageUrlId; + } + + public void setImageUrlId(Integer imageUrlId) { + this.imageUrlId = imageUrlId; + } + + private Integer imageUrlId; + private String productName; + private BigDecimal productPrice; +} diff --git a/app/src/main/java/com/example/register/fragment/SetDetailFragment.java b/app/src/main/java/com/example/register/fragment/SetDetailFragment.java new file mode 100644 index 0000000..cbfbcdd --- /dev/null +++ b/app/src/main/java/com/example/register/fragment/SetDetailFragment.java @@ -0,0 +1,53 @@ +package com.example.register.fragment; + +import android.annotation.SuppressLint; +import android.app.Fragment; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.register.R; +import com.example.register.CategoryActivity; + +import java.util.Objects; + +public class SetDetailFragment extends Fragment { + private View view; + private ImageView imageView; + private TextView nameText, priceText; + + @SuppressLint("SetTextI18n") + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + view = inflater.inflate(R.layout.categoty_detail_content, container, false); + if (view != null) { + init(); + } + CategoryActivity categoryActivity = (CategoryActivity) getActivity(); + Objects.requireNonNull(categoryActivity).setOnChangeListener(product -> { + Log.i("sss", "onCreateView: " + product.getProductName()); + imageView.setBackgroundResource(product.getImageUrlId()); + nameText.setText(product.getProductName()); + priceText.setText(product.getProductPrice().toString()); + }); + return view; + } + + /** + * 内容组件初始化 + */ + private void init() { + imageView = view.findViewById(R.id.category_product_image); + nameText = view.findViewById(R.id.category_product_name); + priceText = view.findViewById(R.id.category_product_price); + } + +} diff --git a/app/src/main/java/com/example/register/userActivity.java b/app/src/main/java/com/example/register/userActivity.java index dc01ba9..828ec7d 100644 --- a/app/src/main/java/com/example/register/userActivity.java +++ b/app/src/main/java/com/example/register/userActivity.java @@ -4,11 +4,18 @@ import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.os.Bundle; import android.content.Intent; +import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; +import android.app.Activity; +import com.example.register.R; +import androidx.annotation.Nullable; -public class userActivity extends AppCompatActivity{ +public class userActivity extends AppCompatActivity implements View.OnClickListener{ EditText username,sex,city; + LinearLayout search; Button exit; @@ -28,6 +35,14 @@ public class userActivity extends AppCompatActivity{ sex = findViewById(R.id.reg_sex); city = findViewById(R.id.reg_address); + search = findViewById(R.id.user_searchProduct); + search.setOnClickListener(this); +// search.setOnClickListener(view -> { +// Intent intent1 =new Intent(); +// Intent.setClass(this,CategoryActivity.class); +// startActivity(intent1); +// }); + exit=findViewById(R.id.exit); exit.setOnClickListener(view -> { Intent intent = new Intent(); @@ -36,6 +51,19 @@ public class userActivity extends AppCompatActivity{ }); } + +// @Override +// public void onClick(View v) { +// switch (v.getId()) { +// case R.id.user_searchProduct: +// Intent intent1 = new Intent(this, CategoryActivity.class); +// startActivity(intent1); +// break; +// } +// } + + + /** * 接收参数 */ @@ -51,4 +79,14 @@ public class userActivity extends AppCompatActivity{ sex.setText("性别: " + sexStr); city.setText("地址: " + cityStr); } -} \ No newline at end of file + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.user_searchProduct: + Intent intent1 = new Intent(userActivity.this, CategoryActivity.class); + startActivity(intent1); + break; + } + } + } diff --git a/app/src/main/res/drawable/arrow_left.png b/app/src/main/res/drawable/arrow_left.png new file mode 100644 index 0000000..365afe0 Binary files /dev/null and b/app/src/main/res/drawable/arrow_left.png differ diff --git a/app/src/main/res/drawable/haorou.jpg b/app/src/main/res/drawable/haorou.jpg new file mode 100644 index 0000000..2a2921a Binary files /dev/null and b/app/src/main/res/drawable/haorou.jpg differ diff --git a/app/src/main/res/drawable/rou.png b/app/src/main/res/drawable/rou.png new file mode 100644 index 0000000..1ca83d8 Binary files /dev/null and b/app/src/main/res/drawable/rou.png differ diff --git a/app/src/main/res/drawable/search.png b/app/src/main/res/drawable/search.png new file mode 100644 index 0000000..a8b5ac0 Binary files /dev/null and b/app/src/main/res/drawable/search.png differ diff --git a/app/src/main/res/drawable/shui.jpg b/app/src/main/res/drawable/shui.jpg new file mode 100644 index 0000000..3527552 Binary files /dev/null and b/app/src/main/res/drawable/shui.jpg differ diff --git a/app/src/main/res/drawable/xiaoshi.jpg b/app/src/main/res/drawable/xiaoshi.jpg new file mode 100644 index 0000000..a0fbd3a Binary files /dev/null and b/app/src/main/res/drawable/xiaoshi.jpg differ diff --git a/app/src/main/res/drawable/yinliao.jpg b/app/src/main/res/drawable/yinliao.jpg new file mode 100644 index 0000000..cce5c77 Binary files /dev/null and b/app/src/main/res/drawable/yinliao.jpg differ diff --git a/app/src/main/res/layout/category_detail.xml b/app/src/main/res/layout/category_detail.xml new file mode 100644 index 0000000..476b522 --- /dev/null +++ b/app/src/main/res/layout/category_detail.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/category_list_item.xml b/app/src/main/res/layout/category_list_item.xml new file mode 100644 index 0000000..2187312 --- /dev/null +++ b/app/src/main/res/layout/category_list_item.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/categoty_detail_content.xml b/app/src/main/res/layout/categoty_detail_content.xml new file mode 100644 index 0000000..a46be2c --- /dev/null +++ b/app/src/main/res/layout/categoty_detail_content.xml @@ -0,0 +1,31 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_category.xml b/app/src/main/res/layout/content_category.xml new file mode 100644 index 0000000..9327e49 --- /dev/null +++ b/app/src/main/res/layout/content_category.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/user.xml b/app/src/main/res/layout/user.xml index 4a72e78..73086f6 100644 --- a/app/src/main/res/layout/user.xml +++ b/app/src/main/res/layout/user.xml @@ -23,12 +23,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" - android:layout_marginTop="40dp" + android:layout_marginTop="20dp" android:orientation="horizontal"> @@ -36,7 +36,7 @@ android:id="@+id/login_name" android:layout_width="310dp" android:layout_height="60dp" - android:textSize="25sp" + android:textSize="20sp" android:hint="username" android:maxLength="16" android:maxLines="1" @@ -50,12 +50,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" - android:layout_marginTop="20dp" + android:layout_marginTop="10dp" android:orientation="horizontal"> @@ -63,7 +63,7 @@ android:id="@+id/reg_sex" android:layout_width="310dp" android:layout_height="60dp" - android:textSize="25sp" + android:textSize="20sp" android:hint="username" android:maxLength="4" android:maxLines="1" @@ -75,12 +75,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" - android:layout_marginTop="20dp" + android:layout_marginTop="10dp" android:orientation="horizontal"> @@ -88,7 +88,7 @@ android:id="@+id/reg_address" android:layout_width="310dp" android:layout_height="60dp" - android:textSize="25sp" + android:textSize="20sp" android:hint="address" android:maxLength="25" android:maxLines="1" @@ -100,19 +100,19 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" - android:layout_marginTop="20dp" + android:layout_marginTop="10dp" android:orientation="horizontal"> - - + + @@ -146,18 +152,18 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" - android:layout_marginTop="20dp" + android:layout_marginTop="10dp" android:orientation="horizontal"> - diff --git a/新建文本文档.txt b/新建文本文档.txt deleted file mode 100644 index e69de29..0000000