• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Launch New screen from a List (2 lists created via Spinner and arrays)

Ali Pudsey

Lurker
Apr 16, 2019
2
0
Im learning to write/develop

I have a spinner as the first option. depending on what I select, one of the two lists appear.
If I select Option A on the spinner , and click the button, I get a LIST of items, i,e LIST-A (from an array)
If I select Option B on the spinner , and click the button, I get a 2nd LIST of items, i,e LIST-B (from an array)

How Can I click on one of the items in the list to open a second page ( say to describe/detail that item )
Say I want to click on APPLE , can I open a second page to have info on Apple
THE LIST WILL VARY on the SPINNER selection ....Position 1 could be APPLE or CABBAGE depending on the spinner selection

Can It be done ?


upload_2019-4-16_20-7-46.png
 

Attachments

  • main.jpg
    main.jpg
    48 KB · Views: 45
How Can I click on one of the items in the list to open a second page ( say to describe/detail that item )
Say I want to click on APPLE , can I open a second page to have info on Apple

There are a couple of ways you could do this:
 
  • Like
Reactions: GameTheory
Upvote 0
What you need is OnItemSelectedListener()

Code:
spinnerA.setOnItemSelectedListener(new OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
       // your code here
   }

   @Override
   public void onNothingSelected(AdapterView<?> parentView) {
       // your code here
   }

});
I am a newbie. Still working my way around ... Are you saying this will on a simple textview list as in my intial screenshot?
 
Upvote 0
I am a newbie. Still working my way around ... Are you saying this will on a simple textview list as in my intial screenshot?
This will invoked when an item in the spinner has been selected.

Example you have a spinner item list for Fruit and Apple is in position 2. So your code mostly looked like this

Java:
spinnerA.setOnItemSelectedListener(new OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
       // your code here
         if(spinnerFruitList.get(position) == 2){
               // Intent to Apple's page
        }
   }
   @Override
   public void onNothingSelected(AdapterView<?> parentView) {
       // your code here
   }
});

For the intent part, you may refer to the link which suggested by @LV426
 
Last edited:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones