Android控件之Menu选择菜单

这个Menu选择菜单选择只要在Activity继承类里实现以下方法就可以了

MyList.java类:
package iaiai.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MyList extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(Menu.NONE, 1, 0, "诊断");
		menu.add(Menu.NONE, 2, 0, "结单");
		menu.add(Menu.NONE, 3, 0, "回复收到");
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public void openOptionsMenu() {
		super.openOptionsMenu();
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		String temp = "";
		switch (item.getItemId()) {
		case 1:
			temp = "诊断";
			break;
		case 2:
			temp = "结单";
			break;
		case 3:
			temp = "回复收到";
			break;
		default:
			break;
		}
		Toast.makeText(this, temp + "處理", Toast.LENGTH_LONG).show();
		return super.onOptionsItemSelected(item);
	}

}

Android控件之Menu选择菜单
Android控件之Menu选择菜单

你可能感兴趣的:(android,OS,ITeye)