This commit is contained in:
ybb 2024-06-19 18:12:16 +08:00
parent 270b863621
commit ef37b4be25
5 changed files with 92 additions and 11 deletions

View File

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

View File

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

View File

@ -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) {

View File

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

View File

@ -16,6 +16,7 @@
app:layout_constraintTop_toBottomOf="@+id/constraintLayout22">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/store_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"