日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 基本事件及对话框

發布時間:2024/6/14 Android 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 基本事件及对话框 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. 在android.view.KeyEvent 中,onKeyDown表示對鍵盤按鍵的響應

? 需要重寫onKeyDown 函數

? @Override

? public boolean onKeyDown(int keyCode, KeyEvent msg){

?

? 存在四種KeyEvent事件 KEYCODE_DPAD_UP、KEYCODE_DPAD_RIGHT、KEYCODE_DPAD_LEFT、KEYCODE_DPAD_DOWN

2在android.view.motionEvent中,.onTouchEvent表示對觸摸屏的響應

? 需要重寫onTouchEvent函數

? @Override

? public boolean onTouchEvent(MotionEvent event) {

? float x = event.getX();

? float y = event.getY();

3.如何實現Activity 跳轉

?Intent intent = new Intent(); // 建立Intent

?intent.setClass(Forwarding.this, ForwardTarget.class); // 設置活動

?startActivity(intent);

?finish(); // 結束當前活動--可選

4.在Activity01中攜帶參數跳轉至Activity02 進行處理,并將處理結果返回給Activity01中的實現步驟

?? 1.Activity01中指定事件中定義調轉

???? Intent intent = new Intent(ReceiveResult.this, SendResult.class);

???? startActivityForResult (intent, GET_CODE);

?? 2.Activity02中,處理完之后將要返回的數據封裝到setAction中。

???? setResult(RESULT_OK, (new Intent()).setAction("Corky!"));

?? 3.Activity01中重寫onActivityResult(int requestCode, int resultCode,Intent data)事件

5.如何添加菜單及響應

?? 1.重寫OnCreateOptionsMenu(Menu menu)函數

?? 2.在函數中,添加menu.add(0,RED_MENU_ID,0,r.string.red);

?? 3.重寫public boolean onOptionsItemSelected(MenuItem item)

?? 4.swith(item.getItemId()){

????? case RED_MENU_ID:

????? break;

???? }

?? abstract MenuItem add(int groupId, int itemId, int order, CharSequence title)

6.彈出式對話框

? android.app.AlertDialog 來實現彈出式對話框

? 使用AlertDialog.Builder和不同的參數來構建對話框。

? return new AlertDialog.Builder(AlertDialogSamples.this) // 返回一個對話框

? .setIcon(R.drawable.alert_dialog_icon)? // 設定icon

? .setTitle(R.string.alert_dialog_two_buttons_title) // 設定title

? .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {

?? ?????public void onClick(DialogInterface dialog, int whichButton) {

??????? /* 左鍵事件 */

??????? }

?? });

? .setNeutralButton(R.string.alert_dialog_something, new DialogInterface.OnClickListener() {

???????? public void onClick(DialogInterface dialog, int whichButton) {

???????? /* 中鍵事件 */

???????? }

? })

?

? .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {

???????? public void onClick(DialogInterface dialog, int whichButton) {

???????? /* 右鍵事件 */

???????? }

? })

?.setMessage(R.string.alert_dialog_two_buttons2_msg) ? //設定消息內容

????????

?.setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() { //列表項對話框

???????? public void onClick(DialogInterface dialog, int which) {

???????? String[] items =getResources().getStringArray(R.array.select_dialog_items);

???????? new AlertDialog.Builder(AlertDialogSamples.this)

?????????????????? .setMessage("You selected: " + which + " , " + items[which])

?????????????????? .show();

???????? }

?})

?.setSingleChoiceItems(R.array.select_dialog_items2, 0, new DialogInterface.OnClickListener() { //單選項和按鈕對話框

???????? public void onClick(DialogInterface dialog, int whichButton) {

???????? }

?})

?.setMultiChoiceItems(R.array.select_dialog_items3,

???????? new boolean[]{false, true, false, true, false, false, false},

???????? new DialogInterface.OnMultiChoiceClickListener() {

?????????????????? public void onClick(DialogInterface dialog, int whichButton,boolean isChecked) { //多選項和按鈕對話框

?????????????????? /* 點擊復選框的響應 */

?????????????????? }

?})

轉載于:https://www.cnblogs.com/oftenlin/archive/2013/03/27/2984674.html

總結

以上是生活随笔為你收集整理的Android 基本事件及对话框的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。