OnClickListener listener = new OnClickListener(){ public void onClick(View v) { setTitle("this is OK button"); } }; OnClickListener listener2 = new OnClickListener() { public void onClick(View v) { finish(); } };
OnClickListener listener3 = new OnClickListener() { public void onClick(View v) { setTitle("this is Cancel button"); } }; }
下面介绍如何呈现List选单 这个程式展现了MVC的基本架构 Activity 对应着的是Controller ListView 对应着的是View DataModel对应着的是Model import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; public class ex05 extends Activity implements OnItemClickListener { public static final int RELOAD_ID = Menu.FIRST; public static final int EXIT_ID = Menu.FIRST + 1; ListView lv; ArrayAdapter adapter; //声明一个泛型adapter DataModel dm; //声明一个数据模型dm @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); dm = new DataModel(); //创建一个模型 lv = new ListView(this); //创建一个列表视图 adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, dm.loadData());