diff --git a/build.gradle.kts b/build.gradle.kts index 8136aa1..9bdd258 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -80,4 +80,6 @@ dependencies { implementation ("com.baidu.lbsyun:BaiduMapSDK_Location:9.3.7") implementation ("com.guolindev.permissionx:permissionx:1.7.1") + // ViewPager2 + } \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020337/GoodsActivity.java b/src/main/java/com/hnucm/c202201020337/GoodsActivity.java index 6b09029..5eaf551 100644 --- a/src/main/java/com/hnucm/c202201020337/GoodsActivity.java +++ b/src/main/java/com/hnucm/c202201020337/GoodsActivity.java @@ -2,7 +2,10 @@ package com.hnucm.c202201020337; //商品选择页面,商品详情,选择口味,加入购物车或者直接购买 import androidx.appcompat.app.AppCompatActivity; +import android.content.Intent; import android.os.Bundle; +import android.view.View; +import android.widget.ImageView; public class GoodsActivity extends AppCompatActivity { @@ -10,5 +13,16 @@ public class GoodsActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_goods); + + ImageView imageView37 = findViewById(R.id.imageView37); + imageView37.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(GoodsActivity.this, MainActivity.class); + intent.putExtra("fragmentToLoad", "OrderingFragment"); // 设置要加载的Fragment为OrderingFragment + startActivity(intent); + finish(); // 关闭当前的StoreActivity + } + }); } } \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020337/IndentFragment.java b/src/main/java/com/hnucm/c202201020337/IndentFragment.java index 0697ea7..1ff7554 100644 --- a/src/main/java/com/hnucm/c202201020337/IndentFragment.java +++ b/src/main/java/com/hnucm/c202201020337/IndentFragment.java @@ -1,7 +1,9 @@ package com.hnucm.c202201020337; - +//main3 +import android.content.Intent; import android.os.Bundle; import androidx.annotation.NonNull; +import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -16,127 +18,51 @@ import java.util.List; public class IndentFragment extends Fragment { - private RecyclerView recyclerViewIndent1; - private MyAdapter_indent1 myAdapterIndent1; - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_indent, container, false); - recyclerViewIndent1 = view.findViewById(R.id.indent1_recyclerview); - recyclerViewIndent1.setLayoutManager(new LinearLayoutManager(getActivity())); - - // 假设有一些示例数据 - List indentItems = new ArrayList<>(); - indentItems.add(new IndentItem("自提", "蜜雪冰城(湖中大内店)", "已完成", "2004-06-02 20:15-10", "1", "10", R.drawable.goods2)); - indentItems.add(new IndentItem("外送", "星巴克(湖中大外店)", "已完成", "2004-06-03 21:15-10", "2", "20", R.drawable.goods2)); - - myAdapterIndent1 = new MyAdapter_indent1(indentItems); - recyclerViewIndent1.setAdapter(myAdapterIndent1); + RecyclerView recyclerView = view.findViewById(R.id.indent1_recyclerview); + MyAdapter_indent myAdapterIndent = new MyAdapter_indent(); + recyclerView.setAdapter(myAdapterIndent); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); return view; } - public class MyViewHolder_indent1 extends RecyclerView.ViewHolder { - TextView type; - TextView storeName; - TextView status; - TextView dateTime; - TextView quantity; - TextView price; - ImageView productImage; - - public MyViewHolder_indent1(@NonNull View itemView) { + public class MyViewHolder_indent extends RecyclerView.ViewHolder{ + TextView name; + public MyViewHolder_indent(@NonNull View itemView) { super(itemView); - type = itemView.findViewById(R.id.textView20); - storeName = itemView.findViewById(R.id.textView21); - status = itemView.findViewById(R.id.textView22); - dateTime = itemView.findViewById(R.id.textView23); - quantity = itemView.findViewById(R.id.textView25); - price = itemView.findViewById(R.id.textView24); - productImage = itemView.findViewById(R.id.imageView9); + name = itemView.findViewById(R.id.textView21); } } - - public class MyAdapter_indent1 extends RecyclerView.Adapter { - private List indentItems; - - public MyAdapter_indent1(List indentItems) { - this.indentItems = indentItems; - } - + public class MyAdapter_indent extends RecyclerView.Adapter{ @NonNull @Override - public MyViewHolder_indent1 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.indend_card, parent, false); - return new MyViewHolder_indent1(view); + public MyViewHolder_indent onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(getActivity()) + .inflate(R.layout.indend_card,parent,false); + return new MyViewHolder_indent(view); } @Override - public void onBindViewHolder(@NonNull MyViewHolder_indent1 holder, int position) { - IndentItem item = indentItems.get(position); - holder.type.setText(item.getType()); - holder.storeName.setText(item.getStoreName()); - holder.status.setText(item.getStatus()); - holder.dateTime.setText(item.getDateTime()); - holder.quantity.setText("共" + item.getQuantity() + "件"); - holder.price.setText("¥" + item.getPrice()); - holder.productImage.setImageResource(item.getImageResource()); + public void onBindViewHolder(@NonNull MyViewHolder_indent holder, int position) { + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // 创建 Intent 实例,从当前 Fragment 跳转到 OrdersActivity + Intent intent = new Intent(getActivity(), OrdersActivity.class); + startActivity(intent); + } + }); } @Override public int getItemCount() { - return indentItems.size(); + return 10; } } - public class IndentItem { - private String type; - private String storeName; - private String status; - private String dateTime; - private String quantity; - private String price; - private int imageResource; - - public IndentItem(String type, String storeName, String status, String dateTime, String quantity, String price, int imageResource) { - this.type = type; - this.storeName = storeName; - this.status = status; - this.dateTime = dateTime; - this.quantity = quantity; - this.price = price; - this.imageResource = imageResource; - } - - public String getType() { - return type; - } - - public String getStoreName() { - return storeName; - } - - public String getStatus() { - return status; - } - - public String getDateTime() { - return dateTime; - } - - public String getQuantity() { - return quantity; - } - - public String getPrice() { - return price; - } - - public int getImageResource() { - return imageResource; - } - } } \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020337/IndentOkFragment.java b/src/main/java/com/hnucm/c202201020337/IndentOkFragment.java index 7fb136d..cb2d3ca 100644 --- a/src/main/java/com/hnucm/c202201020337/IndentOkFragment.java +++ b/src/main/java/com/hnucm/c202201020337/IndentOkFragment.java @@ -1,5 +1,6 @@ package com.hnucm.c202201020337; //订单已完成的Fragment +import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.Fragment; @@ -7,6 +8,7 @@ import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; public class IndentOkFragment extends Fragment { @@ -14,6 +16,20 @@ public class IndentOkFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_indent_ok, container, false); + View view = inflater.inflate(R.layout.fragment_indent_ok, container, false); + + ImageView imageView33 = view.findViewById(R.id.imageView33); + + imageView33.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getActivity(), MainActivity.class); + intent.putExtra("fragmentToLoad", "IndentFragment"); + startActivity(intent); + getActivity().finish(); + } + }); + return view; } + } \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020337/MainActivity.java b/src/main/java/com/hnucm/c202201020337/MainActivity.java index cd1fc46..54a9a22 100644 --- a/src/main/java/com/hnucm/c202201020337/MainActivity.java +++ b/src/main/java/com/hnucm/c202201020337/MainActivity.java @@ -80,7 +80,7 @@ public class MainActivity extends AppCompatActivity { } }); - // 处理从StoreActivity返回的Intent + // 返回mainAC String fragmentToLoad = getIntent().getStringExtra("fragmentToLoad"); if (fragmentToLoad != null) { switch (fragmentToLoad) { @@ -92,14 +92,33 @@ public class MainActivity extends AppCompatActivity { .hide(myFragment) .commit(); break; - default: // 默认情况下,显示HomeFragment,假设这是初始状态 + case "IndentFragment": getSupportFragmentManager().beginTransaction() + .hide(orderingFragment) // 显示OrderingFragment + .hide(homeFragment) + .show(indentFragment) + .hide(myFragment) + .commit(); + break; + + case "MyFragment": + getSupportFragmentManager().beginTransaction() + .hide(orderingFragment) // 显示OrderingFragment + .hide(homeFragment) + .hide(indentFragment) + .show(myFragment) + .commit(); + break; + + case "HomeFragment": + getSupportFragmentManager().beginTransaction() + .hide(orderingFragment) // 显示OrderingFragment .show(homeFragment) - .hide(orderingFragment) .hide(indentFragment) .hide(myFragment) .commit(); break; + } } } diff --git a/src/main/java/com/hnucm/c202201020337/OrderingFragment.java b/src/main/java/com/hnucm/c202201020337/OrderingFragment.java index 948ddcf..f4322fa 100644 --- a/src/main/java/com/hnucm/c202201020337/OrderingFragment.java +++ b/src/main/java/com/hnucm/c202201020337/OrderingFragment.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ImageView; import android.widget.TextView; @@ -37,7 +38,7 @@ public class OrderingFragment extends Fragment { recyclerView2.setAdapter(myAdapterOrder2); recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity())); - //跳转到StoreActivity + //点击-跳转到StoreActivity TextView textView7 = view.findViewById(R.id.textView7); textView7.setOnClickListener(new View.OnClickListener() { @Override @@ -99,7 +100,6 @@ public class OrderingFragment extends Fragment { } public class MyAdapter_order2 extends RecyclerView.Adapter { - @NonNull @Override public MyViewHolder_order2 onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -110,15 +110,22 @@ public class OrderingFragment extends Fragment { @Override public void onBindViewHolder(@NonNull MyViewHolder_order2 holder, int position) { - // holder.goodsImage.setImageResource(R.drawable.goods1); - // holder.goodsName.setText("冰新柠檬水"); - // holder.goodsDescription.setText("大片柠檬看得见,现切现搅超新鲜"); - // holder.goodsPrice.setText("¥4起"); + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // 创建 Intent 实例,从当前 Fragment 跳转到 GoodsActivity + Intent intent = new Intent(getActivity(), GoodsActivity.class); + startActivity(intent); + } + }); } @Override public int getItemCount() { - return 20; // 假设有10个商品 + return 20; } } + + + } \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020337/OrdersActivity.java b/src/main/java/com/hnucm/c202201020337/OrdersActivity.java index 2f099ad..2d120d8 100644 --- a/src/main/java/com/hnucm/c202201020337/OrdersActivity.java +++ b/src/main/java/com/hnucm/c202201020337/OrdersActivity.java @@ -1,5 +1,5 @@ package com.hnucm.c202201020337; -//订单详情页,查看历史订单 +//订单详情页 import androidx.appcompat.app.AppCompatActivity; import androidx.constraintlayout.widget.ConstraintLayout; @@ -19,15 +19,6 @@ public class OrdersActivity extends AppCompatActivity { //布局换Fragment getSupportFragmentManager().beginTransaction().add(R.id.orders_layout,indentOkFragment).commit(); - //返回 - ImageView imageView1 = findViewById(R.id.imageView33); - imageView1.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(OrdersActivity.this,MainActivity.class); - startActivity(intent); - } - }); } } \ No newline at end of file diff --git a/src/main/res/layout/fragment_home.xml b/src/main/res/layout/fragment_home.xml index 32dd33f..85a3645 100644 --- a/src/main/res/layout/fragment_home.xml +++ b/src/main/res/layout/fragment_home.xml @@ -14,14 +14,25 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - + + + + + + + + diff --git a/src/main/res/layout/fragment_indent_ok.xml b/src/main/res/layout/fragment_indent_ok.xml index cffb3e9..3b8adbe 100644 --- a/src/main/res/layout/fragment_indent_ok.xml +++ b/src/main/res/layout/fragment_indent_ok.xml @@ -24,16 +24,6 @@ app:layout_constraintEnd_toEndOf="parent" app:srcCompat="@drawable/xuebao" /> - - + + + app:layout_constraintTop_toTopOf="parent"> diff --git a/src/main/res/layout/order_card.xml b/src/main/res/layout/order_card.xml index fefb339..1f1a14b 100644 --- a/src/main/res/layout/order_card.xml +++ b/src/main/res/layout/order_card.xml @@ -6,6 +6,7 @@ android:layout_height="120dp">