Question

(Android Studio) (Mobile App Development)

Create a spinner that has drop down function on it (NOT tab view). Place a scroll bar inside the dropdown of the spinner. The categories inside the spinner include: vegetable, fruit, meat, drink. Clicking on each section will pop up a fragment section below. Here, I clicked on the vegetable section, which leads me to a page displaying vegetables and their expiration dates.

Note: Post XML and Java codes for both the main activity and the fragments. You only need to create the vegetable fragment, I code the rest based on the vegetable fragment. Do not screenshot the code, please write out the code.

Choose a category:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

activity_main.xml

<?xml version ="1.0" encoding =" utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/Android"

xmlns:tools = "http://schemas.android.com/tools"

android: layout_width =" match_parent"

android: layout_height ="match_parent"

android:orientation = "vertical"

android:weightSum = "3"

tools:context = ".MainActivity">

<LinearLayout

android:layout_width ="match_ parent"

android:layout_ height = "0dp"

android:layout_weight = "1"

android: orientation = "vertical"

android: weightSum = "2"

>

<TextView

android:layout_width = "match_ parent"

android: layout_height = "wrap_content"

android: layout_weight = "1"

android: text = "Choose Category"

android: gravity = "center"

android:textStyle ="bold" android:textSize= "20sp"

/>

<Spinner

android:id = " @+id/spinner"

android:layout_width = "match_parent"

android:layout_height = "36dp"

android:layout_weight= "1"/>

</LinearLayout>

<FrameLayout>

android: id = "@+id/myFrame"

android: layout_width = "match_parent"

android:layout_height ="0dp"

android:layout_weight = "2">

</FrameLayout>

</LinearLayout>

MainActivity.java

public class MainActivity extends Activity{

String[] categories = {"choose category","vegetables","fruit","meat","drink"};

private Spinner mSpinner;

private String Select;

private FragmentManager mFragManager; private FragmentTransaction mFragTransaction; private VegiFragment mVegfragment;

private DrinkFragment mDrinkFragment; private Fruit fragment mFruitFragment; private MeatFragment mMeatFragment;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mVegFragment = new VegiFragment(); mDrinkFragment = new DrinkFragment(): mMeatFragment = new MeatFragment();

mFruitFragment = new FruitFragment():

mSpinner = (Spinner)findViewById(R.id.spinner);

mFragManager = getFragmentManager();

ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this,android.R.id.simple_spinner_item, categories);

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

mSpinner.setAdapter( dataAdapter);

mSpinner.setOnItemSelectedListener(

new AdapterView.OnItemSelectedListner(){

@Override

public void onItmeSelected( AdapterView<?> arg0, View arg1, int arg2, long arg3){

int position = mSpinner.getSelectedItemPosition();

Select = categories [+position];

if( Select == "vegetables"){

if(mFragManager.findFragmentById(R.id.myFrame)== null){

mFragTransaction = mFragManager.beginTransaction();

mFragTransaction.add(R.id.myFrame, mVegFragment);

mFragTransaction.commit();

}

if(mMeatFragment.isResumed()||mDrinkFragment.isResumed()||mFruitFragment.isResumed()){

mFragTransaction = mFragManager.beginTransaction();

mFragTransaction.replace(R.id.myFrame,mmVegFragment);

mFragmentTransaction.commit();}}

if(Select == "meat"){

mFragTransaction = mFragManager.beginTransaction();

if(mVegFragment.isResumed()||mFruitFragment.isResumed()||mDrinkFragment.isResumed()){

mFragTransaction.replace(R.id.myFrame, mMeatFragment);}

mFragmentTransaction.commit();}

// Do same for fruit and drink

}

}

@Override

public void on nothing selected(AdapterView<?> arg0){});

}}

Android Studio File Edit View Navigate Code Analyze Refactor Build Run Tools VCs win: CheggFragments I/Desktop/hemaAndroid/CheggFragments)-.../app/src/main/java/com/he CheggFragments appsrc main)java com hema HomeworkLibfragments MainActivity) ? MainActivity java isi fragment vegi.xml activity main.xml ? VegFragment java - fragment fruit xml ( FruitFre package com. hema. HomeworkLibfragments; import.. 12public class MainActivity extends Activity f 13 String[l categpriesfchoose categories,vegetable, fruit, meat,drink 14 15 16 17 18 19 20 21 private Spinner mSpinner; private String Select; private FragmentManager mFragManager; private FragmentTransaction mFragTransaction; private VegiFragment mVegFragment private DrinkFragment mDrinkFragment; private FruitFragment mFruitFragment; private MeatFragment mMeatFragment; 23 2401 25 26 @override protected void onCreate(Bundle savedInstanceState) t super.onCreate(savedInstanceState); setContentView(R. layout.activity main); 28 29 0 1 mVegFragment = new VegiFragment(); mDrinkFragment new DrinkFragment (); mFruitFragment new FruitFragment (): mMeatFragment = new MeatFragment(); mSpinner-(Spinner)findViewById(R.id.spinner); mFragManager getFragmentManager(); mFragTransaction mFragManager.beginTransaction); MainActivity onCreate)new OnltemSelectedListener Sync Build Run build /Users/juliagonzalez/Desktop/hemaAndroid/CheggFragments Load build Configure build x Calculate task graph

Add a comment
Know the answer?
Add Answer to:
(Android Studio) (Mobile App Development) Create a spinner that has drop down function on it (NOT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use android studio to create a concert ticket mobile application. The app will calculate the total...

    Use android studio to create a concert ticket mobile application. The app will calculate the total cost of concert tickets. These types of apps make it very easy for consumers to buy tickets via their mobile devices. In this app, the user will select an event, enter data, and the mobile app will conduct data processing by performing mathematical calculations. The mobile app details are below: Mobile Application Title: “Ticket Hub” Overview: Provide an app that will calculate the total...

  • (Android Studio) Create a camera app that allows the user to upload a picture from their...

    (Android Studio) Create a camera app that allows the user to upload a picture from their phone camera gallery, see the picture via summary page, and edit the picture as well. Clicking on "Insert picture here from camera photo gallery" in the add page will allow the user to upload a picture from their existing camera photo gallery on their phone. The user can choose where to save the picture, starting with Picture 1-5. Once they choose where to save...

  • • Create an Android Stop Watch mobile application based on the below requirements: ◦ The Stop Watch App will display the...

    • Create an Android Stop Watch mobile application based on the below requirements: ◦ The Stop Watch App will display the time as: ▪ HH:MM:SS.mmmm Where HH represents the number of hours; MM represents the number of minutes; SS represents the number of seconds; mmmm represents the number of milliseconds. For example, ▪ 02:09:57.1234 The above time example would read: ▪ Two hours and ▪ Nine minutes and ▪ Fifty seconds and ▪ One thousands two hundreds thirty four milliseconds...

  • If anyone here is a Java and Android Studio expert please I really need help fulfilling...

    If anyone here is a Java and Android Studio expert please I really need help fulfilling the requirements needed to make a Rock Paper Scissors game. I mainly need Java code to complete it I will post what I have so far I don't have much time left please if anyone can help me I would really appreciate it. Here's what the app is supposed to do... The player should be able to select either Rock, Paper, or Scissors.The app...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT