我正在用一本书“headfirst python”做python练习 使用python和sl4a制作android应用程序 我的代码是
import android
import json
import time
from urllib import urlencode
from urllib2 import urlopen
hello_msg = "Welcome to Coach Kelly's Timing App"
list_title = 'Here is your list of athletes:'
quit_msg = "Quitting Coach Kelly's App."
web_server = 'http://127.0.0.1:8080'
get_names_cgi = '/cgi-bin/generate_name.py'
def send_to_server(url, post_data=None):
if post_data:
page = urlopen(url, urlencode(post_data))
else:
page = urlopen(url)
return(page.read().decode("utf8"))
app = android.Android()
def status_update(msg, how_long=2):
app.makeToast(msg)
time.sleep(how_long)
status_update(hello_msg)
athlete_names = sorted(json.loads(send_to_server(web_server + get_names_cgi)))
app.dialogCreateAlert(list_title)
app.dialogSetSingleChoiceItems(athlete_names)
app.dialogSetPositiveButtonText('Select')
app.dialogSetNegativeButtonText('Quit')
app.dialogShow()
resp = app.dialogGetResponse().result
status_update(quit_msg)
这是我的代码,结果是
怎么了??? 我想不出问题在哪里。。。
使用10.0.2.2:8080
因为如果您在计算机127.0.0.1:(端口)中同时运行服务器和仿真器,本地IP将引用仿真器,那么您需要服务器的另一个本地IP,它将自动成为10.0.2.2
希望我把它弄清楚,很高兴我帮了忙
相关问题 更多 >
编程相关推荐