diff --git a/src/main/java/com/hnucm/c202201020337/HomeFragment.java b/src/main/java/com/hnucm/c202201020337/HomeFragment.java index 4780866..a5c3633 100644 --- a/src/main/java/com/hnucm/c202201020337/HomeFragment.java +++ b/src/main/java/com/hnucm/c202201020337/HomeFragment.java @@ -1,7 +1,9 @@ package com.hnucm.c202201020337; +import android.content.Intent; import android.os.Bundle; +import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; @@ -14,6 +16,12 @@ public class HomeFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_home, container, false); + View view = inflater.inflate(R.layout.fragment_home, container, false); + + CardView cardView5 = view.findViewById(R.id.cardView5); + + + + 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 8d28c54..cd1fc46 100644 --- a/src/main/java/com/hnucm/c202201020337/MainActivity.java +++ b/src/main/java/com/hnucm/c202201020337/MainActivity.java @@ -18,10 +18,6 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - //各种声明 - - //沉浸式 - //ImmersionBar.with(this).init(); //布局换Fragment getSupportFragmentManager().beginTransaction().add(R.id.main_layout,homeFragment).commit(); getSupportFragmentManager().beginTransaction().add(R.id.main_layout,orderingFragment).commit(); @@ -84,7 +80,27 @@ public class MainActivity extends AppCompatActivity { } }); - + // 处理从StoreActivity返回的Intent + String fragmentToLoad = getIntent().getStringExtra("fragmentToLoad"); + if (fragmentToLoad != null) { + switch (fragmentToLoad) { + case "OrderingFragment": + getSupportFragmentManager().beginTransaction() + .show(orderingFragment) // 显示OrderingFragment + .hide(homeFragment) + .hide(indentFragment) + .hide(myFragment) + .commit(); + break; + default: // 默认情况下,显示HomeFragment,假设这是初始状态 + getSupportFragmentManager().beginTransaction() + .show(homeFragment) + .hide(orderingFragment) + .hide(indentFragment) + .hide(myFragment) + .commit(); + break; + } + } + } } - -} \ No newline at end of file diff --git a/src/main/java/com/hnucm/c202201020337/OrderingFragment.java b/src/main/java/com/hnucm/c202201020337/OrderingFragment.java index e154d9a..948ddcf 100644 --- a/src/main/java/com/hnucm/c202201020337/OrderingFragment.java +++ b/src/main/java/com/hnucm/c202201020337/OrderingFragment.java @@ -38,10 +38,7 @@ public class OrderingFragment extends Fragment { recyclerView2.setLayoutManager(new LinearLayoutManager(getActivity())); //跳转到StoreActivity - // Find the TextView by its ID TextView textView7 = view.findViewById(R.id.textView7); - - // Set a click listener on the TextView textView7.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/src/main/java/com/hnucm/c202201020337/StoreActivity.java b/src/main/java/com/hnucm/c202201020337/StoreActivity.java index 16c1792..b5d74f3 100644 --- a/src/main/java/com/hnucm/c202201020337/StoreActivity.java +++ b/src/main/java/com/hnucm/c202201020337/StoreActivity.java @@ -1,9 +1,18 @@ package com.hnucm.c202201020337; //门店选择页面,上面地图,下面列表 //Q8O8got5iAChLBTSXYGAwQUwbKe06Ekd +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import android.content.Intent; import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; public class StoreActivity extends AppCompatActivity { @@ -11,5 +20,55 @@ public class StoreActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_store); + + RecyclerView recyclerView = findViewById(R.id.store_recyclerview); + StoreMapAdapter adapter = new StoreMapAdapter(); + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + + + //点击-返回 + ImageView imageView29 = findViewById(R.id.imageView29); + imageView29.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(StoreActivity.this, MainActivity.class); + intent.putExtra("fragmentToLoad", "OrderingFragment"); // 设置要加载的Fragment为OrderingFragment + startActivity(intent); + finish(); // 关闭当前的StoreActivity + } + }); } + + public class MyViewHolder extends RecyclerView.ViewHolder { + TextView textView48; + public MyViewHolder(@NonNull View itemView) { + super(itemView); + textView48 = itemView.findViewById(R.id.textView48); + // 初始化 store_map_card 中的其他 View + } + } + public class StoreMapAdapter extends RecyclerView.Adapter{ + @NonNull + @Override + public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.store_map_card, parent, false); + return new MyViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { + + } + + @Override + public int getItemCount() { + return 10; + } + } + + + } \ No newline at end of file diff --git a/src/main/res/layout/activity_store.xml b/src/main/res/layout/activity_store.xml index 301192c..6f8a113 100644 --- a/src/main/res/layout/activity_store.xml +++ b/src/main/res/layout/activity_store.xml @@ -16,6 +16,7 @@ app:layout_constraintTop_toBottomOf="@+id/constraintLayout22">