首页 > 其他 > 详细

ActionBar Fragment的一个sample activity

时间:2014-05-10 07:49:46      阅读:323      评论:0      收藏:0      [点我收藏+]
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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!