我有一個活動,它調用一個對話框......在對話框中我要求用戶輸入一個密碼。現在我需要這個密碼在我的activity.Is它可能和如何??? ...預先感謝! !將對話框中的數據傳遞給對話框的調用活動?
1
A
回答
0
看一看這個討論AlertDialog Input Text ..
所有你需要的是當按下相應的按鈕(正或負)來調用的意圖。
在這裏看到:
Intent intent=new Intent(context,AnotherActivity.class);
EditText mUserText;
mUserText = (EditText) textEntryView.findViewById(R.id.txt_password);
String strpwd = mUserText.getText().toString();
intent.putExtra("my_password",strpwd);
startActivity(intent);
1
您可以創建一個活動,是themed as a Dialog
<activity android:theme="@android:style/Theme.Dialog">
,然後描述here調用活動與startActivityForResult(...)
。
0
在onClick
偵聽器中,您將通過當前Dialog
作爲方法參數之一。
因此,您可以在onClick
方法中執行類似((TextView) dialog.findViewById(R.id.passwordField)).getText().toString()
的操作。