码迷,mamicode.com
首页 > 其他好文 > 详细

ActionBar Fragment的一个sample activity

时间:2014-05-10 07:49:35      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   code   java   

bubuko.com,布布扣
public class MainActivity extends ActionBarActivity {
    private static ActivityManager am;
    private static List<RunningAppProcessInfo>  appList;
    private static List<RunningTaskInfo> taskList; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment()).commit();
        }
        
        
        am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        
        appList = am.getRunningAppProcesses();
        taskList = am.getRunningTasks(100);
        
        for(RunningAppProcessInfo info: appList){
            Log.d("linsen",""+info.processName);
        }
        for(RunningTaskInfo info: taskList){
            Log.i("linsen", ""+info.topActivity);
        }
        
        
    }



    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {
        private Button btn2;
        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container,
                    false);
            btn2  = (Button) rootView.findViewById(R.id.button1);
            btn2.setOnClickListener(new OnClickListener() {
                
                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    
                    am.moveTaskToFront(taskList.get(4).id,0);
                    Log.w("linsen","btn2 onclicked");
                    moveTask();
                }

                
            });
            return rootView;
        }
    }
    private static void moveTask() {
        // TODO Auto-generated method stub
        
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
bubuko.com,布布扣

 About Fragment, there are 3 import methods:     Fragment.onCreateView;     Activity.getSupportFragmentManager;  FragmentManager.beginTransaction; 

 Fragment.onCreateView;    

Activity.getSupportFragmentManager;  

FragmentManager.beginTransaction; 

ActionBar Fragment的一个sample activity,布布扣,bubuko.com

ActionBar Fragment的一个sample activity

标签:android   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/linxiaojiang/p/3719303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!