安卓的简单开发应用

安卓系统开发简单应用
 
MainActivity
 
package com.example.tianqi;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	
	private Button btn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		btn=(Button)findViewById(R.id.button1);
		btn.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent in=new Intent(MainActivity.this,FirstMainActivity.class);
				startActivity(in);
			}});
	}

	@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;
	}

}
 
ThirdMainActivity
 
SecMainActivity
package com.example.tianqi;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ThirdMainActivity extends Activity 
{
	private Button btn;
	private Button btn1;

	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_third_main);
		btn=(Button)findViewById(R.id.button1);
		btn.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent in6=new Intent();
				in6.setAction(Intent.ACTION_SENDTO);
				in6.setData(Uri.parse("smsto:13000000000"));
				in6.putExtra("sms body", "");
				startActivity(in6);
				
			}});
		btn1=(Button)findViewById(R.id.Button01);
		btn1.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent in7=new Intent(ThirdMainActivity.this,FirstMainActivity.class);
				startActivity(in7);
				
			}});
		}
	


	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.third_main, menu);
		return true;
	}

}


 
SecMainActivity
 
package com.example.tianqi;

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

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

public class SecMainActivity extends Activity {
	private ListView userlv;
	List list;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sec_main);
		userlv=(ListView)findViewById(R.id.listView1);
		list=new ArrayList();
		list.add("(0)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		list.add("(1)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		list.add("(2)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		list.add("(3)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		list.add("(4)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		list.add("(5)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		list.add("(6)发送者:13000000000,2013-7-16 02:30:10,中国,China,Clear,30,Fri,Mostly Sunny,30/30");
		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.
		getMenuInflater().inflate(R.menu.sec_main, menu);
		return true;
	}

}
FirstMainActivity
 
package com.example.tianqi;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class FirstMainActivity extends Activity {

	final static int menu_tianqi=Menu.FIRST;
	final static int menu_history=Menu.FIRST+1;
	final static int menu_set=Menu.FIRST+2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_first_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.first_main, menu);
		menu.add(0,menu_tianqi,0,"天气预报").setIcon(android.R.drawable.btn_star_big_on);
		menu.add(0,menu_history,1,"历史数据").setIcon(android.R.drawable.btn_star_big_on);
		menu.add(0,menu_set,2,"系统设置").setIcon(android.R.drawable.btn_star_big_on);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		//return super.onOptionsItemSelected(item);
		switch(item.getItemId()){
		case menu_tianqi:
			System.out.println("menu_tainqi");
			Intent in1=new Intent(FirstMainActivity.this,FirstMainActivity.class);
			startActivity(in1);
			return true;
		case menu_history:
			System.out.println("menu_history");
			Intent in2=new Intent(FirstMainActivity.this,SecMainActivity.class);
			startActivity(in2);
			return true;
		case menu_set:
			System.out.println("menu_set");
			Intent in3=new Intent(FirstMainActivity.this,ThirdMainActivity.class);
			startActivity(in3);
			return true;
		}
		return false;
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		//return super.onPrepareOptionsMenu(menu);
		return true;
	}

}


 

你可能感兴趣的:(安卓的简单开发应用)