我在我的活動中調用方法ShowDialog。我有一個名稱列表,所以我將在這個名稱列表中循環,併爲每個名稱,我會得到它的數字。有些名字可能只有一個數字,其他的名字可能有更多。如果一個名稱的數量超過一個,我會顯示另一個對話框,提示您選擇所需的數字。Android - 另一個對話框內的對話框 - 如何知道它們何時完成切除?
當所有的名字都只有一個數字,它是容易的,我叫dialog.dismiss,然後SendSMS(listOfNumbers),並最終完成():
ShowDialog();
SendSMS(listOfNumbers);
finish();
但是,當用戶擁有多個號碼出現問題。當過程結束時,我無法找到讓我知道的方法。
的ShowDialog()方法:
protected void ShowDialog() {
final Dialog dialog = new Dialog(ContactsPicker.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.alert_dialog);
final CheckBox cbE = (CheckBox) dialog.findViewById(R.id.checkBoxEmail);
final CheckBox cbN = (CheckBox) dialog.findViewById(R.id.checkBoxNumber);
Button button = (Button) dialog.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String names = "";
String names1 = "";
String names2 = "";
if (cbN.isChecked()) {
//Send invitations through SMS
//List<String> numbers = new ArrayList<String>();
String number = "";
List<String> usernumbers = new ArrayList<String>();
//Fill names string to send it back
for (int i = 0; i < selected.size(); i++) {
//number = get_Number(contactName, getApplicationContext());
usernumbers = getNumber(selected.get(i), getApplicationContext());
//Toast.makeText(getApplicationContext(),"Usernumbers list size: "+usernumbers.size(),Toast.LENGTH_SHORT).show();
if (usernumbers.size() == 1) {
selectedNumbers.add(usernumbers.get(0));
} else if (usernumbers.size() > 1) {
//Show select number dialog
dialog.hide();
showSelectNumberPopup(usernumbers);
} else {
}
//dialog.show();
}
}
if (cbE.isChecked()) {
//Send invitations through e-mail
List<String> emails = new ArrayList<String>();
String email = "";
for (String contactName : selected) {
email = get_Email(contactName, getApplicationContext());
emails.add(email);
names2 += contactName + ",";
}
//showToast("Send E-mail Checked");
sendEmail(emails);
}
}
});
}
而且showSelectNumberPopup方法:
protected void showSelectNumberPopup(List<String> usernumbers) {
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.alert_dialog_select_number, null);
// vi = LayoutInflater.from(getBaseContext()).inflate(R.layout.alert_dialog_select_number,null);
//View view = (View)getLayoutInflater().inflate(R.layout.alert_dialog_select_number, null);
dialogLV = (ListView) view.findViewById(R.id.list_select_number);
dialogLV.setAdapter(new SelectNumberDialogListAdapter(getApplicationContext(), usernumbers));
dialogLV.setItemsCanFocus(false);
dialogLV.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
dialogLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
String selectedFromList = (String) (dialogLV.getItemAtPosition(myItemInt));
cbSelectedNumber = (CheckBox) myView.findViewById(R.id.checkBoxNumber);
if (selectedNumbers.contains(selectedFromList)) {
selectedItemCB.setChecked(false);
selectedNumbers.remove(selectedFromList);
//Toast.makeText(getApplicationContext(), "Removed From SELECTED: " + selectedFromList, Toast.LENGTH_SHORT).show();
} else {
selectedItemCB.setChecked(true);
selectedNumbers.add(selectedFromList);
//Toast.makeText(getApplicationContext(), "Added To SELECTED: " + selectedFromList, Toast.LENGTH_SHORT).show();
}
}
});
final Dialog dialog = new Dialog(ContactsPicker.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
//Toast.makeText(getApplicationContext(),"GOT IN THE SECOND POPUP",Toast.LENGTH_SHORT).show();
Button button = (Button) dialog.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
if (names1 != "")
names = names1;
else if (names2 != "")
names = names2;
else {
for (String contactName : selected) {
names += contactName + ",";
}
}
names = names.substring(0, names.lastIndexOf(","));
//Set data to send it back to PickNamesActivity
Intent data = new Intent();
//---set the data to pass back---
data.setData(Uri.parse(names));
setResult(RESULT_OK, data);
//finish();
//sendSMS(selectedNumbers);
//finish();
dialog.show();
}
你可以使用dialog.isShowing()方法來檢查它是否可見或被忽略。 –
第二個對話框可能會被多次調用,那麼isShowing應該如何幫助? – Hussain