0

我正在尝试手动设置当我单击 YES 或 NO 按钮时会发生什么Dialog。有我的代码。(对不起,我英语不好)

  Dialog D = new Dialog(Dialog.D_YES_NO, "Comprar Recarga", 0, Bitmap.getBitmapResource("icon.png"),Dialog.EDITABLE);
  D.add(List_tipo);
  D.add(List_valor);
  D.add(List_num_conta);
  D.show(); 
  if(D.getSelectedValue()==Dialog.OK)
  {

    int Recarga, num_conta;
    Recarga = Integer.parseInt(List_valor.getChoice(List_valor.getSelectedIndex()).toString());
    num_conta = Integer.parseInt(List_num_conta.getChoice(List_num_conta.getSelectedIndex()).toString());
    int tipo = List_tipo.getSelectedIndex();
    if(tipo==0)
    {
        recargas_existentes.comprar_mcel(Recarga, num_conta); 
    }
    if(tipo==1)
    {
        recargas_existentes.comprar_vodacom(Recarga, num_conta); 
    }
    if(tipo==2)
    {
        recargas_existentes.comprar_bla_bla(Recarga, num_conta); 
    }

  }
4

1 回答 1

2

您应该能够使用 Dialog 的 doModal() 方法。

这是一个很好的例子: https ://stackoverflow.com/a/10681171/2415100

如果你不能使用 doModal,试试这个:

public class ProceedPrompt extends PopupScreen
{
    int response = Dialog.NO;

    private ProceedPrompt(String message)
    {
        super(new VerticalFieldManager());
        LabelField labelField = new LabelField(message, USE_ALL_WIDTH | DrawStyle.HCENTER);
        add(labelField);

        ButtonField button_proceed = new ButtonField(
                "Proceed", USE_ALL_WIDTH | FIELD_HCENTER)
        {
            protected boolean navigationClick(int status, int time)
            {
                response = Dialog.YES;
                close();
                return true;
            }
        };

        ButtonField button_cancel = new ButtonField(
                "Cancel", USE_ALL_WIDTH | FIELD_HCENTER)
        {
            protected boolean navigationClick(int status, int time)
            {
                response = Dialog.NO;
                close();
                return true;
            }
        };

        add(button_proceed);
        add(button_cancel);
    }

    public static int doModal(String s)
    {
        ProceedPrompt prompt = new ProceedPrompt(s);
        UiApplication.getUiApplication().pushModalScreen(prompt);
        return prompt.response;
    }

}

然后调用

int i = ProceedPrompt.doModal("Did this work?");
于 2013-06-20T16:50:30.633 回答