-1

Hello everyone I'm working on my Android project where I created expandable list view with Men's and Women's sports. Under each of them I have a list of sports. Each sport after you click on it open new activity. Example: If you click on Men's sports then Baseball you will open new activity where you get listed all Baseball events from database. I'm on that point where I created my expandable list view and my activities for each sport, now I have to populate each sport from data base. My data base is sorted in array-list from 0 to 11. Here is how it looks my database sorted in array-list:

 this   Main  (id=831962574768) 
groupedFeeds    ArrayList  (id=831963150464)    
    array   Object[12]  (id=831963153088)   
        [0] GroupedFeed  (id=831963152968)  
            category    "Women's Golf" (id=831962986192)    
            feeds   ArrayList  (id=831963152992)    
        [1] GroupedFeed  (id=831963153592)  
            category    "Volleyball" (id=831962991720)  
            feeds   ArrayList  (id=831963153616)    
        [2] GroupedFeed  (id=831963153744)  
            category    "Men's Soccer" (id=831962996544)    
            feeds   ArrayList  (id=831963153768)    
        [3] GroupedFeed  (id=831963153896)  
            category    "Women's Soccer" (id=831963006320)  
            feeds   ArrayList  (id=831963153920)    
        [4] GroupedFeed  (id=831963154864)  
            category    "Men's Golf" (id=831963016488)  
            feeds   ArrayList  (id=831963154888)    
        [5] GroupedFeed  (id=831963155072)  
            category    "Men's Cross Country" (id=831963036816) 
            feeds   ArrayList  (id=831963155096)    
        [6] GroupedFeed  (id=831963155224)  
            category    "Women's Cross Country" (id=831963041984)   
            feeds   ArrayList  (id=831963155248)    
        [7] GroupedFeed  (id=831963155472)  
            category    "Men's Bowling" (id=831963093056)   
            feeds   ArrayList  (id=831963155496)    
        [8] GroupedFeed  (id=831963155712)  
            category    "Women's Bowling" (id=831963098224) 
            feeds   ArrayList  (id=831963155736)    
        [9] GroupedFeed  (id=831963155864)  
            category    "Women's Basketball" (id=831963170720)  
            feeds   ArrayList  (id=831963155888)    
        [10]    GroupedFeed  (id=831963157504)  
            category    "Men's Basketball" (id=831963299944)    
            feeds   ArrayList  (id=831963157528)    
        [11]    null    
    modCount    11  
    size    11  
loader  RSSLoader  (id=831962575480)    
aMan    AssetManager  (id=831962469744) 

Now I have to populate my Expandable List View for each Sport(Activity). Here is my Main method where I have to create function to populate my sports. I put the comments where that function suppose to be and how I think that should populate inside of the ecah sport. Please if someone can help I'm stuck and can not figure it out.

 public class MainActivity<View> extends ActionBarActivity {

        ExpandableListView exv;
        List<GroupedFeed> gfList;
        GroupedFeed gfResult;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            exv=(ExpandableListView)findViewById(R.id.expandableListView1);
            exv.setAdapter(new MyAdapter(this));
            exv.setOnChildClickListener(new OnChildClickListener() {

                **// Create GroupedFeed findFeed(String locateSport);

                public boolean onChildClick(ExpandableListView parent,
                        android.view.View v, int groupPosition, int childPosition,
                        long id) {
                    switch (groupPosition)
                    {
                    case 0:
                            switch (childPosition)
                            {
                            case 0:

                                **// Call gfResult = findFeed("Men's Baseball");
                                Baseball();  **// pass gfResult
                                break;
                            case 1:
                                MensBasketball();
                                break;
                            case 2:
                                MensBowling();
                                break;
                            case 3:
                                MensCross_Country();
                                break; 
                            case 4:
                                MensGolf();
                                break;
                            case 5:
                                MensSoccer();
                                break;
                            case 6:
                                MensTrack_Field();
                                break;
                            }
                         break;
                      case 1:
                            switch (childPosition)
                            {
                             case 0:
                                WomensBasketball();
                                break;
                            case 1:
                                WomensBowling();
                                break;
                            case 2:
                                WomensCross_Country();
                                break; 
                            case 3:
                                WomensGolf();
                                break;
                            case 4:
                                WomensSoccer();
                                break;
                           case 5:
                                Softball();
                                break;
                            case 6:
                                WomensTrack_Field();
                                break;
                            case 7:
                                Volleyball();
                                break;
                            }

                    }
                    return false;
                }

                private void Baseball() {
                    Intent myIntent = new Intent(MainActivity.this, Baseball.class);
                    startActivity(myIntent);
                }

                private void MensBasketball() {
                    Intent myIntent = new Intent(MainActivity.this, MensBasketball.class);
                    startActivity(myIntent);
                }

                private void WomensBasketball() {
                    Intent myIntent = new Intent(MainActivity.this, WomensBasketball.class);
                    startActivity(myIntent);
                }

                private void MensBowling() {
                    Intent myIntent = new Intent(MainActivity.this, MensBowling.class);
                    startActivity(myIntent);
                }

                private void WomensBowling() {
                    Intent myIntent = new Intent(MainActivity.this, WomensBowling.class);
                    startActivity(myIntent);
                }

                private void MensCross_Country() {
                    Intent myIntent = new Intent(MainActivity.this, MensCross_Country.class);
                    startActivity(myIntent);
                }

                private void WomensCross_Country() {
                    Intent myIntent = new Intent(MainActivity.this, WomensCross_Country.class);
                    startActivity(myIntent);
                }

                private void MensGolf() {
                    Intent myIntent = new Intent(MainActivity.this, MensGolf.class);
                    startActivity(myIntent);
                }   

                private void WomensGolf() {
                    Intent myIntent = new Intent(MainActivity.this, WomensGolf.class);
                    startActivity(myIntent);
                }  

                private void MensSoccer() {
                    Intent myIntent = new Intent(MainActivity.this, MensSoccer.class);
                    startActivity(myIntent);
                }

                private void WomensSoccer() {
                    Intent myIntent = new Intent(MainActivity.this, WomensSoccer.class);
                    startActivity(myIntent);
                }

                private void Softball() {
                    Intent myIntent = new Intent(MainActivity.this, Softball.class);
                    startActivity(myIntent);
                }

                private void MensTrack_Field() {
                    Intent myIntent = new Intent(MainActivity.this, MensTrack_Field.class);
                    startActivity(myIntent);
                }

                private void WomensTrack_Field() {
                    Intent myIntent = new Intent(MainActivity.this, WomensTrack_Field.class);
                    startActivity(myIntent);
                }

                private void Volleyball() {
                    Intent myIntent = new Intent(MainActivity.this, Volleyball.class);
                    startActivity(myIntent);
                }

            });   
            Main myMain = new Main();
            try {
            //  AssetManager aMan = getAssets();
    //          @SuppressWarnings("unused")
                this.gfList = myMain.loadRSS();
            } catch (Exception e) {
                System.out.println("Hosed");
            }
        }
    }
espresso_coffee
  • 5,980
  • 11
  • 83
  • 193
  • Instead of calling function in on child click call on Baseball or other activity. – Haresh Chhelana Dec 05 '14 at 04:39
  • Can you provide any code for that please? – espresso_coffee Dec 05 '14 at 04:58
  • There is no need for any code you have to just call your commented code in each activity detail instead of switch case inside child on click. – Haresh Chhelana Dec 05 '14 at 05:00
  • So should I make like this: gdResult = findFeed("Men's Baseball"); and then Baseball(gfResult); break; ? I do not understand what I have to replace instead of switch? – espresso_coffee Dec 05 '14 at 05:33
  • What should I do with GroupedFeed findFeed(String locateSport)? And should I pass gfResult inside of Baseball under switch statement or all the way down where I created new activity for Baseball? Thanks in advance – espresso_coffee Dec 05 '14 at 20:01

1 Answers1

0

The easiest way to do this would be to pass the data to the activity in the intent you're using to start the activity:

Intent intent = new Intent(getBaseContext(), YourActivity.class);
intent.putExtra("youe_data_key", yourData);
startActivity(intent);
Zeeshan Ahmed
  • 1,179
  • 2
  • 13
  • 30