예, AlertDialogs를 자동화 코드에 표시하는 더 좋은 방법이 있지만 프로덕션 코드에서 AlertDialog를 사용해야합니다. 그것은 당신의 인생을 훨씬 쉽게 만들 것이기 때문에 그것은 가치가있을 것입니다. 설명하겠습니다.
AlertDialogs를 WeakHashMap 개체에 할당하고 매우 쉽게 검색 할 수 있습니다. 여기 방법 -
당신은 단순히 수행 대화 상자가 나타납니다 기대 테스트 프레임 워크에서 지금
//Definition for WeakHashMap Object
WeakHashMap< Integer, Dialog > managedDialogs = new WeakHashMap< Integer, Dialog >();
//Some alertdialog builder that needs to be exposed
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(YourActivity.this);
switch(id)
{
case DIALOG:
alertDialogBuilder.setTitle("some title")
.setMessage("some message")
.setPositiveButton("button text", Onclick activity)
.setNeutralButton("button text", Onclick activity)
.setNegativeButton("button text", Onclick activity)
.setCancelable(true);
AlertDialog dialog = alertDialogBuilder.create();
//Assigning the value of this dialog to the Managed WeakHashMap
managedDialogs.put(DIALOG, dialog);
return dialog;
}
-
AlertDialog dialog = (AlertDialog) activity.managedDialogs.get(YourActivity.DIALOG);