//History.java
package com.example.second; 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 HistoryActivity extends Activity { private ListView userlv; //创建集合对象 List list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history); userlv=(ListView)findViewById(R.id.list); //重点:listview实现依赖于适配器,而适配器又依赖于数据源 //3.创建集合数据源 list=new ArrayList();//初始化对象 //向集合对象加入数据 list.add("(0)发送者:1008611 2012-12-24 09:39" + " New York 阴天"); list.add("(1)发送者:100860000 2013-02-04 19:49" + " Beijing 中雨"); list.add("(2)发送者:18363853390 2013-03-12 14:02" + " Rizhao 晴天"); list.add("(3)发送者:10086 2013-07-20 22:39" + " Dalian 晴天"); //4.创建适配器对象 //参1:表示当前适配器的宿主,必须写。 //参2:表示当前适配器的数据源呈现形式。用简单列表的形式呈现数据 //参3:表示数据源 ArrayAdapter<String> adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list); //5.把适配器绑定到listview控件中 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.history, menu); return true; } }
//Setting.java
package com.example.second; 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 SettingActivity extends Activity { private Button ok; private Button off; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setting); ok=(Button)findViewById(R.id.ok_set); off=(Button)findViewById(R.id.off_set); ok.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent in=new Intent(SettingActivity.this,SecondActivity.class); startActivity(in); }}); off.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent in2=new Intent(SettingActivity.this,SecondActivity.class); startActivity(in2); }}); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.setting, menu); return true; } }