MainActivity.Java:
- package com.example.weatherdemo;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.MenuItem;
- public class MainActivity extends Activity {
- //定义菜单项
- final static int menu_one = Menu.FIRST;
- final static int menu_sec = Menu.FIRST + 1;
- final static int menu_tri = Menu.FIRST + 2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- //getMenuInflater().inflate(R.menu.sec, menu);
- menu.add(0,menu_one,0,"天气预报").setIcon(android.R.drawable.btn_star);
- menu.add(0,menu_sec,1,"历史数据").setIcon(android.R.drawable.btn_star);
- menu.add(0,menu_tri,2,"系统设置").setIcon(android.R.drawable.btn_star);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- switch(item.getItemId())
- {
- case menu_one:
- return true;
- case menu_sec:
- Intent in = new Intent(MainActivity.this,SecActivity.class);
- finish();
- startActivity(in);
- return true;
- case menu_tri:
- Intent in2 = new Intent(MainActivity.this,TriActivity.class);
- finish();
- startActivity(in2);
- return true;
- }
- return false;
- }
- }
SecActivity.Java:
- package com.example.weatherdemo;
- 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 SecActivity extends Activity {
- //定义菜单项
- final static int menu_one = Menu.FIRST;
- final static int menu_sec = Menu.FIRST + 1;
- final static int menu_tri = Menu.FIRST + 2;
- private ListView userlv;
- List list;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_sec);
- userlv=(ListView)findViewById(R.id.userlv);
- list=new ArrayList();
- list.add("星期一");
- list.add("星期二");
- list.add("星期三");
- list.add("星期四");
- list.add("星期五");
- list.add("星期六");
- list.add("星期七");
- ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
- userlv.setAdapter(adapter);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- menu.add(0,menu_one,0,"天气预报").setIcon(android.R.drawable.btn_star);
- menu.add(0,menu_sec,1,"历史数据").setIcon(android.R.drawable.btn_star);
- menu.add(0,menu_tri,2,"系统设置").setIcon(android.R.drawable.btn_star);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- switch(item.getItemId())
- {
- case menu_one:
- Intent in = new Intent(SecActivity.this,MainActivity.class);
- finish();
- startActivity(in);
- return true;
- case menu_sec:
- return true;
- case menu_tri:
- Intent in2 = new Intent(SecActivity.this,TriActivity.class);
- finish();
- startActivity(in2);
- return true;
- }
- return false;
- }
- }
TriActivity.java:
- package com.example.weatherdemo;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.MenuItem;
- public class TriActivity extends Activity {
- //定义菜单项
- final static int menu_one = Menu.FIRST;
- final static int menu_sec = Menu.FIRST + 1;
- final static int menu_tri = Menu.FIRST + 2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_tri);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- menu.add(0,menu_one,0,"天气预报").setIcon(android.R.drawable.btn_star);
- menu.add(0,menu_sec,1,"历史数据").setIcon(android.R.drawable.btn_star);
- menu.add(0,menu_tri,2,"系统设置").setIcon(android.R.drawable.btn_star);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- switch(item.getItemId())
- {
- case menu_one:
- Intent in2 = new Intent(TriActivity.this,MainActivity.class);
- finish();
- startActivity(in2);
- return true;
- case menu_sec:
- Intent in = new Intent(TriActivity.this,SecActivity.class);
- finish();
- startActivity(in);
- return true;
- case menu_tri:
- return true;
- }
- return false;
- }
- }
activity_main.xml:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <ImageView
- android:id="@+id/imageView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginLeft="116dp"
- android:layout_marginTop="170dp"
- android:src="@drawable/ic_launcher" />
- <ImageView
- android:id="@+id/imageView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/imageView1"
- android:layout_marginTop="51dp"
- android:layout_toLeftOf="@+id/imageView3"
- android:src="@drawable/ic_launcher" />
- <ImageView
- android:id="@+id/imageView5"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignTop="@+id/imageView4"
- android:layout_marginLeft="33dp"
- android:layout_toRightOf="@+id/imageView1"
- android:src="@drawable/ic_launcher" />
- <ImageView
- android:id="@+id/imageView4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/imageView1"
- android:layout_alignTop="@+id/imageView2"
- android:layout_marginLeft="32dp"
- android:src="@drawable/ic_launcher" />
- <ImageView
- android:id="@+id/imageView3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignRight="@+id/imageView1"
- android:layout_alignTop="@+id/imageView4"
- android:layout_marginRight="19dp"
- android:src="@drawable/ic_launcher" />
- </RelativeLayout>
activity_sec.xml:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".SecActivity" >
- <ListView
- android:id="@+id/userlv"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true" >
- </ListView>
- </RelativeLayout>
activity_tri.xml:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".TriActivity" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginTop="26dp"
- android:text="@string/city" />
- <EditText
- android:id="@+id/editText1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/textView1"
- android:layout_alignBottom="@+id/textView1"
- android:layout_toRightOf="@+id/textView1"
- android:ems="10" >
- <requestFocus />
- </EditText>
- <EditText
- android:id="@+id/editText2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/textView2"
- android:layout_alignBottom="@+id/textView2"
- android:layout_toLeftOf="@+id/editText1"
- android:layout_toRightOf="@+id/textView2"
- android:ems="10"
- android:inputType="number" />
- <TextView
- android:id="@+id/textView3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/editText2"
- android:layout_alignBottom="@+id/editText2"
- android:layout_alignLeft="@+id/editText1"
- android:layout_marginLeft="14dp"
- android:text="@string/time2" />
- <TextView
- android:id="@+id/textView4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView2"
- android:layout_below="@+id/editText2"
- android:layout_marginTop="23dp"
- android:text="@string/message" />
- <CheckBox
- android:id="@+id/checkBox1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/textView4"
- android:layout_alignBottom="@+id/textView4"
- android:layout_toRightOf="@+id/textView4"
- android:text="@string/message2" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView1"
- android:layout_below="@+id/editText1"
- android:layout_marginTop="26dp"
- android:text="@string/time" />
- <TextView
- android:id="@+id/textView5"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView4"
- android:layout_below="@+id/checkBox1"
- android:layout_marginTop="28dp"
- android:text="@string/message3" />
- <CheckBox
- android:id="@+id/checkBox2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/textView5"
- android:layout_alignBottom="@+id/textView5"
- android:layout_toRightOf="@+id/textView5"
- android:text="@string/message2" />
- <EditText
- android:id="@+id/editText3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/textView6"
- android:layout_alignBottom="@+id/textView6"
- android:layout_toRightOf="@+id/textView6"
- android:ems="10" />
- <TextView
- android:id="@+id/textView6"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/textView5"
- android:layout_below="@+id/checkBox2"
- android:layout_marginTop="51dp"
- android:text="@string/message4" />
- </RelativeLayout>