现在我从API中得到了所有的数据,并在Homefragment中显示了它,现在我想要下一个片段的标题,称为overviewFragment。实际上,overviewfragment在emptyactivity中,那么现在如何将数据从一个片段传递到另一个片段。MostCrowdedRecyclerAdapter
@NonNull
@Override
public TopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_layout_layout_5, parent, false);
return new TopViewHolder(view);
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull TopViewHolder holder, int position) {
holder.restaurantName.setText(list.get(position).getName());
holder.distance.setText(list.get(position).getDistance() + " Mile");
vybeAPI = Float.valueOf(list.get(position).getVybe());
holder.vybe.setText(vybeAPI + "%");
// setAnimation(holder.itemView, position);
holder.v.setOnClickListener(v -> { < -- here I did
Intent i = new Intent(v.getContext(), EmptyActivity.class);
i.putExtra("Restaurant", getItemId(position));
context.startActivity(i);
});
}
@Override
public int getItemCount() {
int limit = 6;
return Math.min(list.size(), limit);
}
OverViewFragment:
String data;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_over_view, container, false);
TextView singletitle = view.findViewById(R.id.single);
try {
data = String.valueOf(Intent.getIntent("Restaurant").getExtras());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
这里,我需要将title从homefragment传递到overviewfragment,但是overviewfragment处于EmptyActivity中。