package com.example.second;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class SecondActivity extends Activity {
	
	
	//1.定义菜单项,类型为全局静态的整数
	final static int menu_forecast=Menu.FIRST;
	final static int menu_history=Menu.FIRST+1;
	final static int menu_setting=Menu.FIRST+2;	
	
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_second);
	}//onCreate
	
    //2.菜单第一次生成时所要执行的内容,且只执行一次
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		//getMenuInflater().inflate(R.menu.second, menu);
		
		//把每一个菜单项加入到菜单对象menu中
		menu.add(0,menu_forecast, 0, "天气预报").setIcon(android.R.drawable.alert_light_frame);
        //加系统中(android.R)的图片

		menu.add(0, menu_history, 1, "历史数据").setIcon(android.R.drawable.ic_lock_silent_mode);

		menu.add(0, menu_setting, 2, "系统设置").setIcon(android.R.drawable.btn_dropdown);
		
		return true;
	}//onCreateOptionsMenu

    //3.用户每次选择菜单时都执行;判断用户选了哪个菜单,从而做出跳转
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		//return super.onOptionsItemSelected(item);
	switch(item.getItemId()){
		
	case menu_forecast:
		System.out.println("menu_forecast");
		Intent in4=new Intent(SecondActivity.this,ForecastActivity.class);
		startActivity(in4);
		return true;
	case menu_history:
		System.out.println("menu_history");
		Intent in5=new Intent(SecondActivity.this,HistoryActivity.class);
		startActivity(in5);
		return true; 
	case menu_setting:
		System.out.println("menu_setting");
		Intent in6=new Intent(SecondActivity.this,SettingActivity.class);
		startActivity(in6);
		return true;
	}//switch
	
		
		return false;
	}//onOptionsItemSelected

//4.对应于onCreateOptionsMenu方法
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		//return super.onPrepareOptionsMenu(menu);
		return true;
	}
	

}//class SecondActivity