Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having difficulties with a specific part of my Android Studio programming assignment. The question is: Launch your DetalsActivity using Intents. We will use

I am having difficulties with a specific part of my Android Studio programming assignment. The question is:

Launch your DetalsActivity using Intents. We will use Intents to display the DetailsActivity when someone selects an item in our Items/ListFragment. Edit your MainActivity public void onListFragmentInteraction(String x, int id)method to:

1. Create an intent that will launch your DetailsActivity.

2. Use putExtra to pass the String data to the intent - you pass putExtras a name value pair.

3. Use putExtra to pass the position data to the intent - you pass putExtras a name value pair.

4. Use putExtra to pass the page (fragment) that is currently active (e.g. I used page2, fragName.isVisible() to pass whether page2 was the visible page launching the DetailsActivity).

5. Remember the name(s) you use because you will need it in the next step.

6. Start the DetailsActivity.

My current code for MainActivity.java (The intent we are required to build I have built at the bottom. I believe it has errors):

package edu.ucdenver.contactlistultimate; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.app.FragmentManager; import android.app.FragmentTransaction; public class MainActivity extends Activity implements ItemFragment.OnListFragmentInteractionListener { private static final String TAG = "Contact List"; private FragmentManager mFragmentManager; private ItemFragment contactfrag; private ItemFragment detailsfrag; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "MainActivity onCreate"); setContentView(R.layout.activity_main); mFragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); contactfrag =ItemFragment.newInstance("Contacts"); detailsfrag =ItemFragment.newInstance("Details"); fragmentTransaction.add(R.id.List_Frame, contactfrag, "contactfrag"); Log.i(TAG, "MainActivity add Fragment"); fragmentTransaction.commit(); Log.i(TAG, "MainActivity commit Fragment"); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected (MenuItem item) { int id = item.getItemId(); if (id == R.id.action_home) { if (detailsfrag != null && detailsfrag.isVisible()) { mFragmentManager.beginTransaction().remove(detailsfrag).commit(); mFragmentManager.beginTransaction().add(R.id.List_Frame, contactfrag).commit(); } } else if (id == R.id.action_Contacts) { if (contactfrag != null && contactfrag.isVisible()) { mFragmentManager.beginTransaction().remove(contactfrag).commit(); mFragmentManager.beginTransaction().add(R.id.List_Frame, detailsfrag).commit(); } } return true; } public void onListFragmentInteraction(String x, int id) { Intent launchDetails = new Intent(MainActivity.this, DetailsActivity.class); launchDetails.putExtra(String, "intentstring"); launchDetails.putExtra(int, "intentint"); launchDetails.putExtra("page2", detailsfrag.isVisible()); startActivity(launchDetails); } } 

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions