Mobile Application

Anonymous
timer Asked: Nov 16th, 2016

Question description

Application

Follow the steps in Activity10.1 attached below.Get screenshots and explain the different parts of your app.

Questions

Answer and explain the following questions:

1. In what version of Android was the concept of a Fragment introduced?

a. Android 2.3

b. Android 3.0

c. Android 3.4

d. Android 4.0

2. In your workplace, you are required to support devices running Android 1.6. How would you use fragments?

a. You can't.

b. Add this import to your application manifest file: #backwardCompatibilty.

c. Import Fragment from the android.support.v4.app.Fragment package.

d. Use the java.x class to ensure compatibility.

3. Which of the following is not a benefit of using Fragment components?

a. Fragment components improve battery life.

b. Fragment components greatly improve code reuse.

c. Fragment components simplify testing needs.

d. Fragment components make publication and application package management much less cumbersome.

4. Within what must a Fragment be hosted?

a. A View class

b. The <uses-sdk> tag

c. An Activity class

d. The <uses-configuration> tag

5. An update or modification to a Fragment is performed using what?

a. A FragmentView

b. A FragmentEdit

c. A FragmentActivity

d. A FragmentTransaction

6. Which callback method is called when the Fragment’s user interface becomes visible but is

not yet active?

a. onStart()

b. onCreateView()

c. onResume()

d. onPause()

7. When is the onDestroy() callback method called?

a. When a Fragment is first attached to a specific Activity class

b. Just before the Fragment is detached from the Activity class

c. When the parent Activity is stopped

d. To clean up any other resources associated with the Fragment

8. If a device is in portrait mode, the VeggieGardenViewActivity is launched via what?

a. A Fragment class

b. An Intent

c. An integer resource

d. Resource files

9. What type of Fragment components will be updated via add or replace?

a. Changeable Fragment components

b. Standard Fragment components

c. Dynamic Fragment components

d. Simple Fragment components

10. The Android team provided a compatibility library so that developers can update their legacy applications to use fragments as far back as what version of Android?

a. Android 3.0

b. Android 2.3.7

c. Android 1.6

d. Android 1.5

Refer below attached file for Activity10.1


Activity 10.1 Android Fragment Android fragments example project comprises of a single activity holding two fragments: TextFragment and MenuFragment respectively. Android Fragment Example Code The MainActivity holds the two fragments TextFragment and MenuFragment. So let’s begin with defining the fragments in the xml layout. activity_main.xml MainActivity package com.example.fragmentexample; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } As we can see the class files of the fragments that are a part of this activity are defined as class=” com.example.fragmentexample.TextFragment” Page 1 of 4 The fragment classes and their layouts are defined as shown in the snippets below. The TextFragment comprises of textviews holding the android version name and number. package com.example.fragmentexample; import import import import import import android.app.Fragment; android.os.Bundle; android.view.LayoutInflater; android.view.View; android.view.ViewGroup; android.widget.TextView; public class TextFragment extends Fragment { TextView text,vers; @Override public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_text, container, false); text= (TextView) view.findViewById(R.id.AndroidOs); vers= (TextView)view.findViewById(R.id.Version); return view; } public void change(String txt, String txt1){ text.setText(txt); vers.setText(txt1); } } fragment_text.xml Page 2 of 4 MenuFragment package com.example.fragmentexample; import import import import import import import android.app.ListFragment; android.os.Bundle; android.view.LayoutInflater; android.view.View; android.view.ViewGroup; android.widget.ArrayAdapter; android.widget.ListView; public class MenuFragment extends ListFragment { String[] AndroidOS = new String[] { "Cupcake","Donut","Eclair","Froyo","Gingerbread","Honeycomb","Ice Cream SandWich","Jelly Bean","KitKat" }; String[] Version = new String[]{"1.5","1.6","2.0-2.1","2.2","2.3","3.03.2","4.0","4.1-4.3","4.4"}; @Override public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view =inflater.inflate(R.layout.fragment_menu, container, false); ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, AndroidOS); setListAdapter(adapter); return view; } @Override public void onListItemClick(ListView l, View v, int position, long id) { TextFragment txt = (TextFragment)getFragmentManager().findFragmentById(R.id.fragment2); txt.change(AndroidOS[position],"Version : "+Version[position]); getListView().setSelector(android.R.color.holo_blue_dark); } } fragment_menu.xml The MenuFragment displays a ListView. As we can see here, the layout of ListView is default simple_list_item_1. It's a very simple and standard example of ListView, using the built-in android.R.layout.simple_list_item_1 layout. Page 3 of 4 The MainActivity invokes the setContentView from the onCreate Method, that’s it. The fragments are called from the xml file. Page 4 of 4
Activity 10.1 Android Fragment Android fragments example project comprises of a single activity holding two fragments: TextFragment and MenuFragment respectively. Android Fragment Example Code The MainActivity holds the two fragments TextFragment and MenuFragment. So let’s begin with defining the fragments in the xml layout. activity_main.xml MainActivity package com.example.fragmentexample; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } As we can see the class files of the fragments that are a part of this activity are defined as class=” com.example.fragmentexample.TextFragment” Page 1 of 4 The fragment classes and their layouts are defined as shown in the snippets below. The TextFragment comprises of textviews holding the android version name and number. package com.example.fragmentexample; import import import import import import android.app.Fragment; android.os.Bundle; android.view.LayoutInflater; android.view.View; android.view.ViewGroup; android.widget.TextView; public class TextFragment extends Fragment { TextView text,vers; @Override public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_text, container, false); text= (TextView) view.findViewById(R.id.AndroidOs); vers= (TextView)view.findViewById(R.id.Version); return view; } public void change(String txt, String txt1){ text.setText(txt); vers.setText(txt1); } } fragment_text.xml Page 2 of 4 MenuFragment package com.example.fragmentexample; import import import import import import import android.app.ListFragment; android.os.Bundle; android.view.LayoutInflater; android.view.View; android.view.ViewGroup; android.widget.ArrayAdapter; android.widget.ListView; public class MenuFragment extends ListFragment { String[] AndroidOS = new String[] { "Cupcake","Donut","Eclair","Froyo","Gingerbread","Honeycomb","Ice Cream SandWich","Jelly Bean","KitKat" }; String[] Version = new String[]{"1.5","1.6","2.0-2.1","2.2","2.3","3.03.2","4.0","4.1-4.3","4.4"}; @Override public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState) { View view =inflater.inflate(R.layout.fragment_menu, container, false); ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, AndroidOS); setListAdapter(adapter); return view; } @Override public void onListItemClick(ListView l, View v, int position, long id) { TextFragment txt = (TextFragment)getFragmentManager().findFragmentById(R.id.fragment2); txt.change(AndroidOS[position],"Version : "+Version[position]); getListView().setSelector(android.R.color.holo_blue_dark); } } fragment_menu.xml The MenuFragment displays a ListView. As we can see here, the layout of ListView is default simple_list_item_1. It's a very simple and standard example of ListView, using the built-in android.R.layout.simple_list_item_1 layout. Page 3 of 4 The MainActivity invokes the setContentView from the onCreate Method, that’s it. The fragments are called from the xml file. Page 4 of 4

Tutor Answer

(Top Tutor) Studypool Tutor
School: UC Berkeley
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors