Qpython3 和 androidhelper,droid.dialogSetSingleChoiceItems
Qpython3 and androidhelper, droid.dialogSetSingleChoiceItems
我正在尝试找出 androidhelper,我发现它对 python 3 和 Android 非常有用。我正在尝试 return 使用 dialogSetChoiceItems 从列表中进行选择。我已经设置好了,并且尝试了各种方法来解决它。我会得到一些 returned,但它是列表的长度。任何帮助,将不胜感激。谢谢,
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
import androidhelper
droid = androidhelper.Android()
def test_alert_dialog_with_single_choice_list(Title, ListOfStuff):
droid.dialogCreateAlert(Title)
droid.dialogSetSingleChoiceItems(ListOfStuff)
droid.dialogSetPositiveButtonText('Select')
droid.dialogShow()
response = droid.dialogGetSelectedItems().result
return response
if __name__ == '__main__':
Listy = [1,2,3,4,5,6,7,8]
YTitle = 'Title of The Thing'
FReturn = test_alert_dialog_with_single_choice_list(YTitle, Listy)
print(FReturn)
此示例创建一个对话框,其中包含 "xyz" 个按钮和 "abcde" 个项目,然后是 print(pressed_button, selected_items_indexes)
,以及 makeToast
您按下的按钮和选定的项目。尝试一下!它在我的 phone 上运行良好,请告诉我它是否在你的 phone.
上运行
#-*-coding:utf8;-*-
#qpy:2
#qpy:console
import androidhelper
droid=androidhelper.Android()
def mydialog(title,buttons=["OK"],items=[],multi=False):
title = str(title)
droid.dialogCreateAlert(title)
if len(items) > 0:
if multi:
droid.dialogSetMultiChoiceItems(items)
else:
droid.dialogSetSingleChoiceItems(items)
if len(buttons) >= 1:
droid.dialogSetPositiveButtonText(buttons[0])
if len(buttons) >= 2:
droid.dialogSetNeutralButtonText(buttons[1])
if len(buttons) >= 3:
droid.dialogSetNegativeButtonText(buttons[2])
droid.dialogShow()
res0 = droid.dialogGetResponse().result
res = droid.dialogGetSelectedItems().result
if "which" in res0.keys():
res0={"positive":0,"neutral":1,"negative":2}[res0["which"]]
else:
res0=-1
return res0,res
items = [i for i in "abcde"]
btns = [i for i in "xyz"]
pressed_button, selected_items_indexes = mydialog("Dialog test!", btns, items, True)
print(pressed_button, selected_items_indexes)
if pressed_button == -1:
droid.makeToast("You didn't press any buttons!")
else:
droid.makeToast("You pressed %s!"%("xyz"[pressed_button]))
if selected_items_indexes == []:
droid.makeToast("You selected nothing!")
else:
selected_abc = "".join(["abcde"[i] for i in selected_items_indexes])
droid.makeToast("You selected %s!"%selected_abc)
我正在尝试找出 androidhelper,我发现它对 python 3 和 Android 非常有用。我正在尝试 return 使用 dialogSetChoiceItems 从列表中进行选择。我已经设置好了,并且尝试了各种方法来解决它。我会得到一些 returned,但它是列表的长度。任何帮助,将不胜感激。谢谢,
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
import androidhelper
droid = androidhelper.Android()
def test_alert_dialog_with_single_choice_list(Title, ListOfStuff):
droid.dialogCreateAlert(Title)
droid.dialogSetSingleChoiceItems(ListOfStuff)
droid.dialogSetPositiveButtonText('Select')
droid.dialogShow()
response = droid.dialogGetSelectedItems().result
return response
if __name__ == '__main__':
Listy = [1,2,3,4,5,6,7,8]
YTitle = 'Title of The Thing'
FReturn = test_alert_dialog_with_single_choice_list(YTitle, Listy)
print(FReturn)
此示例创建一个对话框,其中包含 "xyz" 个按钮和 "abcde" 个项目,然后是 print(pressed_button, selected_items_indexes)
,以及 makeToast
您按下的按钮和选定的项目。尝试一下!它在我的 phone 上运行良好,请告诉我它是否在你的 phone.
#-*-coding:utf8;-*-
#qpy:2
#qpy:console
import androidhelper
droid=androidhelper.Android()
def mydialog(title,buttons=["OK"],items=[],multi=False):
title = str(title)
droid.dialogCreateAlert(title)
if len(items) > 0:
if multi:
droid.dialogSetMultiChoiceItems(items)
else:
droid.dialogSetSingleChoiceItems(items)
if len(buttons) >= 1:
droid.dialogSetPositiveButtonText(buttons[0])
if len(buttons) >= 2:
droid.dialogSetNeutralButtonText(buttons[1])
if len(buttons) >= 3:
droid.dialogSetNegativeButtonText(buttons[2])
droid.dialogShow()
res0 = droid.dialogGetResponse().result
res = droid.dialogGetSelectedItems().result
if "which" in res0.keys():
res0={"positive":0,"neutral":1,"negative":2}[res0["which"]]
else:
res0=-1
return res0,res
items = [i for i in "abcde"]
btns = [i for i in "xyz"]
pressed_button, selected_items_indexes = mydialog("Dialog test!", btns, items, True)
print(pressed_button, selected_items_indexes)
if pressed_button == -1:
droid.makeToast("You didn't press any buttons!")
else:
droid.makeToast("You pressed %s!"%("xyz"[pressed_button]))
if selected_items_indexes == []:
droid.makeToast("You selected nothing!")
else:
selected_abc = "".join(["abcde"[i] for i in selected_items_indexes])
droid.makeToast("You selected %s!"%selected_abc)