0

I am trying to set manually what happens when i click YES or NO button in Dialog. There is my code. (Sorry i am not good in english)

  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); 
    }

  }
Nate
  • 31,017
  • 13
  • 83
  • 207

1 Answers1

2

you should be able to use Dialog's doModal() method.

Here's a good example: https://stackoverflow.com/a/10681171/2415100

If you can't use doModal, try this:

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;
    }

}

Then call with

int i = ProceedPrompt.doModal("Did this work?");
Community
  • 1
  • 1
Kevin
  • 1,626
  • 16
  • 30
  • Thanks but doModal() its for BBOS 7.1, and my app needs do run at BBOS5. Any other sugestion???(Sorry iam not good in english) – Afonso Matlhombe Junior Jun 20 '13 at 17:03
  • Ah that's sligtly worse but not too bad. You can create a class that extends PopupScreen, store a local variable for the response (1,2,3,etc). Push that screen, and after it's been popped get the response. – Kevin Jun 20 '13 at 17:13
  • Hmm, i will try it... Iam new in Blackberry programming. So do you have an example of a class that extends PopupScreen. I want to see it before start searching for... Thank you. (Sorry iam not good in english) – Afonso Matlhombe Junior Jun 20 '13 at 17:25
  • I do, just added it to my answer :) – Kevin Jun 20 '13 at 17:27