如何使用数据填充我的体育活动?

时间:2014-12-05 04:29:10

标签: java android arraylist populate

大家好,我正在开发我的Android项目,在那里我使用男士和女士运动创建了可扩展的列表视图。在他们每个人的下面我有一份运动清单。点击它后,每项运动都会开启新的活动。示例:如果您单击Men's sports然后选择棒球,您将打开新活动,其中列出了来自数据库的所有棒球事件。我正是在这一点上我创建了可扩展列表视图和我为每项运动开展的活动,现在我必须从数据库中填充每项运动。我的数据库在数组列表中从0到11排序。以下是我在数组列表中排序数据库的方式:

 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) 

现在我必须为每个运动(活动)填充我的可扩展列表视图。这是我的主要方法,我必须创建功能来填充我的运动。我把评论放在那个函数假设的位置,以及我认为应该如何填充ecah体育。如果有人能帮助我,我会被困住,无法弄清楚。

 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");
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

最简单的方法是将数据传递给您用于启动活动的意图中的活动:

Intent intent = new Intent(getBaseContext(), YourActivity.class);
intent.putExtra("youe_data_key", yourData);
startActivity(intent);