Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, i'm trying to pass a data bundle from one activity to a fragment but i'm not sure what to name the variables i'm passing.

Hi, i'm trying to pass a data bundle from one activity to a fragment but i'm not sure what to name the variables i'm passing. It's not allowing me to just put the variables as name, height and mass. Here's the github link if you want to view the full project https://github.com/kyllaros25/App.git

This is the fragment class that is going to be receiving the data:

public class DetailsFragment extends Fragment { private Bundle dataFromActivity;

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { dataFromActivity = getArguments(); View view = inflater.inflate(R.layout.fragment_details, container, false); TextView nameText = (TextView) view.findViewById(R.id.textName); nameText.setText(dataFromActivity.getString(MainActivity.name)); //not sure what to put here for the variable in bold TextView heightText = (TextView) view.findViewById(R.id.textHeight); heightText.setText(dataFromActivity.getString(MainActivity.height)); //not sure what to put here for the variable in bold TextView massText = (TextView) view.findViewById(R.id.textMass); massText.setText(dataFromActivity.getString(MainActivity.mass)); //not sure what to put here for the variable in bold

Here is the part of my MainActivity class which passes the bundle:

listView.setOnItemClickListener((list, item, position, id) -> { name = jsonModels.get(position).getName(); height = jsonModels.get(position).getHeight(); mass = jsonModels.get(position).getMass(); Bundle dataToPass = new Bundle(); dataToPass.putString("name", name); dataToPass.putString("name", height); dataToPass.putString("mass", mass);

and finally my jsonModels class:

public class JsonModel { private String name; private String height; private String mass; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getHeight() { return height; } public void setHeight(String height) { this.height = height; } public String getMass() { return mass; } public void setMass(String mass) { this.mass = mass; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sales Force Management Leadership Innovation Technology

Authors: Mark W. Johnston, Greg W. Marshall

12th Edition

1138951722, 978-1138951723

More Books

Students also viewed these Programming questions

Question

What are the three kinds of research types? Explain each type.

Answered: 1 week ago