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

歡迎訪問 生活随笔!

生活随笔

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

Android

android 对话框 重复,如何在Android上重复使用AlertDialog for Yes / No?

發布時間:2025/3/12 Android 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 对话框 重复,如何在Android上重复使用AlertDialog for Yes / No? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在嘗試找到重用顯示自定義標題的Dialog的方法,然后將Yes / No click發送到已啟動Dialog的功能.

我有兩個按鈕,保存和解除,并且都調用是/否對話,一個顯示“你想保存”,另一個顯示“關閉更改?”.

我認為我的程序非常“臟”但我想它可以工作,但我的問題是“查看視圖”變量,我不知道如何將它從Activity傳遞給Dialog,所以我可以用它來回憶啟動Dialog的功能.

提前致謝,

HerniHdez

我活動的.java(片段)

public void open_HH_Fragment_YesNo(View view,String aux_title,String aux_function)

{

Bundle bundle=new Bundle();

bundle.putString("setMessage",aux_title);

bundle.putString("callingFunction",aux_function);

DialogFragment newFragment = new HH_Fragment_YesNo();

newFragment.setArguments(bundle);

newFragment.show(getSupportFragmentManager(),"HH_Fragment_YesNo");

}

public void SaveChanges(View view,String aux_YesNo)

{

if (aux_YesNo == "")

{

Toast.makeText(this,"Save changes?",Toast.LENGTH_SHORT).show();

open_HH_Fragment_YesNo(view,"SaveChanges");

}

else if (aux_YesNo == "Yes")

{

Toast.makeText(this,"Saving changes",Toast.LENGTH_SHORT).show();

}

else if (aux_YesNo == "No")

{

Toast.makeText(this,"Save Cancelled",Toast.LENGTH_SHORT).show();

}

}

public void DismissChanges(View view,"Dismiss changes?","DismissChanges");

}

else if (aux_YesNo == "Yes")

{

Toast.makeText(this,"Dismiss OK",Toast.LENGTH_SHORT).show();

Close(view);

}

else if (aux_YesNo == "No")

{

Toast.makeText(this,"Dismiss Cancelled",Toast.LENGTH_SHORT).show();

}

}

// The dialog fragment receives a reference to this Activity through the

// Fragment.onAttach() callback,which it uses to call the following methods

// defined by the HH_Fragment_YesNo.YesNoDialogListener interface

@Override

public void onDialogPositiveClick(DialogFragment dialog,View view,String aux_function)

{

// User touched the dialog's positive button

Toast.makeText(this,"User clicked on Yes",Toast.LENGTH_SHORT).show();

if (aux_function == "SaveChanges")

{

SaveChanges(view,"Yes");

}

else if (aux_function == "DismissChanges")

{

DismissChanges(view,"Yes");

}

}

@Override

public void onDialogNegativeClick(DialogFragment dialog,String aux_function)

{

Toast.makeText(this,"User clicked on NO","No");

}

else if (aux_function == "DismissChanges")

{

DismissChanges(view,"No");

}

}

我的對話的.java(完整)

public class HH_Fragment_YesNo extends DialogFragment

{

@Override

public Dialog onCreateDialog(Bundle savedInstanceState)

{

// Use the Builder class for convenient dialog construction

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

String setMessage = getArguments().getString("setMessage");

final String callingFunction = getArguments().getString("callingFuntion");

builder

.setMessage(setMessage) // R.string.dialog_fire_missiles

.setPositiveButton("Sí",new DialogInterface.OnClickListener() // R.string.fire

{

public void onClick(DialogInterface dialog,int id)

{

// Exit without saving

mListener.onDialogPositiveClick(HH_Fragment_YesNo.this,view,callingFunction);

}

})

.setNegativeButton("No",new DialogInterface.OnClickListener() // R.string.cancel

{

public void onClick(DialogInterface dialog,int id)

{

// User cancelled the dialog

mListener.onDialogNegativeClick(HH_Fragment_YesNo.this,callingFunction);

}

});

// Create the AlertDialog object and return it

return builder.create();

}

/* The activity that creates an instance of this dialog fragment must

* implement this interface in order to receive event callbacks.

* Each method passes the DialogFragment in case the host needs to query it. */

public interface YesNoDialogListener

{

public void onDialogPositiveClick(DialogFragment dialog,String aux_Function);

public void onDialogNegativeClick(DialogFragment dialog,String aux_Function);

}

// Use this instance of the interface to deliver action events

YesNoDialogListener mListener;

// Override the Fragment.onAttach() method to instantiate the NoticeDialogListener

@Override

public void onAttach(Activity activity)

{

super.onAttach(activity);

// Verify that the host activity implements the callback interface

try

{

// Instantiate the NoticeDialogListener so we can send events to the host

mListener = (YesNoDialogListener) activity;

}

catch (ClassCastException e)

{

// The activity doesn't implement the interface,throw exception

throw new ClassCastException(activity.toString() + " must implement NoticeDialogListener");

}

}

}

總結

以上是生活随笔為你收集整理的android 对话框 重复,如何在Android上重复使用AlertDialog for Yes / No?的全部內容,希望文章能夠幫你解決所遇到的問題。

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