master
unknown 2 years ago
parent 049605506c
commit 4d495ea566

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RenderSettings">
<option name="showDecorations" value="true" />
</component>
</project>

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
package="com.example.register">
<application
android:allowBackup="true"
@ -26,6 +27,7 @@
<activity android:name=".registerActivity"> </activity>
<activity android:name=".userActivity"> </activity>
<activity android:name=".CategoryActivity" />
</application>

@ -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<Product> productList;
private List<String> 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);
}
}

@ -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);
}
}

@ -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<String> productCategory;
private LayoutInflater layoutInflater;
private int selectionPosition = -1;
public Adapter(List<String> 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;
}
}

@ -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;
}

@ -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);
}
}

@ -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);
}
}
@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;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 KiB

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="@+id/category_detail_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:gravity="center"/>
</LinearLayout>

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/categor_titles"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="标题" />
</LinearLayout>

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/category_product_image"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center" />
<TextView
android:id="@+id/category_product_name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="#050505"
android:textSize="16sp" />
<TextView
android:id="@+id/category_product_price"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:gravity="center"
android:textColor="#050505"
android:textSize="16sp" />
</LinearLayout>

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E8E8E8"
android:orientation="vertical">
<!--标题-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#EFB81C"
android:orientation="horizontal">
<ImageView
android:id="@+id/category_return"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/arrow_left" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:gravity="center"
android:text="商品种类"
android:textColor="#FFF"
android:textSize="20sp" />
</LinearLayout>
<!--分类标题和内容-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!--标题-->
<!--内容-->
<ListView
android:id="@+id/category_title_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/category_detail"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
</LinearLayout>
</LinearLayout>

@ -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">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/user" />
@ -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">
<ImageView
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/sex" />
@ -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">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/address"/>
@ -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">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/red" />
<EditText
android:layout_width="310dp"
android:layout_height="60dp"
android:textSize="25sp"
android:textSize="20sp"
android:hint="money"
android:maxLength="10"
android:maxLines="1"
@ -121,24 +121,30 @@
</LinearLayout>
<LinearLayout
android:id="@+id/user_searchProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal" />
<EditText
android:layout_width="310dp"
<TextView
android:drawableLeft="@drawable/search"
android:layout_width="165dp"
android:layout_height="60dp"
android:textSize="25sp"
android:textSize="20sp"
android:hint="search"
android:maxLines="1"
android:text="查看订单" />
<TextView
android:layout_width="165dp"
android:layout_height="60dp"
android:textSize="20sp"
android:hint="search"
android:maxLines="1"
android:text="点餐" />
</LinearLayout>
@ -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">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal" />
<EditText
<TextView
android:layout_width="310dp"
android:layout_height="60dp"
android:textSize="25sp"
android:textSize="20sp"
android:hint="set"
android:maxLines="1"
android:text="设置" />

Loading…
Cancel
Save