//用Fragment实现在一个activity根据不同的事件显示不同的界面

package com.example.ex_elepmt.duomi;

import com.example.duomimusic.R;

import android.os.Bundle;

import android.support.v4.app.Fragment;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

/**

* 歌单activity

* @author Administrator

*

*/

public class SongListFragment extends Fragment

{

   @Override

   public View onCreateView(LayoutInflater inflater, ViewGroup container,

           Bundle savedInstanceState)

   {

       View layout = inflater.inflate(R.layout.activity_songlist, null);

       return layout;

   }

}

//在MainActivity中根据不同的事件new不同的fragment

package com.example.duomimusic;

import com.example.duomimusic.utils.Shakespeare;

import com.example.ex_elepmt.duomi.CommonHeader;

import com.example.ex_elepmt.duomi.RankingFragment;

import com.example.ex_elepmt.duomi.RecommendFragment;

import com.example.ex_elepmt.duomi.SongList;

import android.os.Bundle;

import android.app.Activity;

import android.support.v4.app.Fragment;

import android.support.v4.app.FragmentActivity;

import android.support.v4.app.FragmentTransaction;

import android.support.v4.widget.DrawerLayout;

import android.view.LayoutInflater;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.ArrayAdapter;

import android.widget.BaseAdapter;

import android.widget.FrameLayout;

import android.widget.ImageView;

import android.widget.ListView;

import android.widget.RelativeLayout;

import android.widget.TextView;

public class MainActivity extends FragmentActivity

{

   private RelativeLayout mSildingMenu;

   private ListView mListView;

   public  DrawerLayout mDrawrLayut;

   private TextView mTvCommonTitle;

   @Override

   protected void onCreate(Bundle savedInstanceState)

   {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);      

       

  findViewById(R.id.bottom).setOnClickListener(new OnClickListener()

       {

           @Override

           public void onClick(View v)

           {

                   

                   FragmentTransaction ft =   getSupportFragmentManager().beginTransaction();

                   Fragment myfragment = new  SongListFragment();    

                  ft.add(R.id.header, myfragment);

                   ft.commit();

                       }

       });

}

}