我试图手动设置当我在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);
}
}
答案 0 :(得分: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?");