Andorid Enter 回车事件

OnKeyListener keyListener = new OnKeyListener()
	{
		public boolean onKey(View v, int keyCode, KeyEvent event)
		{
			if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP)
			{
				String keyword = mKeywordtxt.getText().toString();
				if (keyword != "")
				{
					Intent intent = new Intent();
					intent.setClass(BusinessCenterListActivity.this, ParkSearchResultActivity.class);
					intent.putExtra("localLongitude", mLocalLongitude);
					intent.putExtra("localLatitude", mLocalLatitude);
					intent.putExtra("key", keyword);

					startActivity(intent);
				}

				return true;
			}
			return false;
		}
	};

mKeywordtxt.setOnKeyListener(keyListener);

备注:如果没有加这个条件event.getAction() == KeyEvent.ACTION_UP 会执行两次你的操作

你可能感兴趣的:(andorid)