首页 > 代码库 > ActionBar Fragment的一个sample activity
ActionBar Fragment的一个sample activity
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); } }
About Fragment, there are 3 import methods: Fragment.onCreateView; Activity.getSupportFragmentManager; FragmentManager.beginTransaction;
Fragment.onCreateView;
Activity.getSupportFragmentManager;
FragmentManager.beginTransaction;
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。