我正在做一个用户可以输入比赛卡丁车号码的项目,它会显示相应的卡丁车比赛详情。但我不确定如何将编辑文本值添加到AsyncTask中的URL。
代码
int kartNumber = Integer.parseInt(etGokart.getText().toString());
.......
.......
protected JSONObject doInBackground(String... urls) {
try {
URL url = new URL("http://race.speedtiming.com/api/index.php/races/scoreboard.json?track_id=3");//**-->how to include kart number there in url**
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
..........
..........
}
答案 0 :(得分:0)
希望这有帮助
int kartNumber = Integer.parseInt(etGokart.getText().toString());
String urlWithoutKartNum = "http://race.speedtiming.com/api/index.php/races/scoreboard.json?track_id=#kart_num#";
.......
.......
protected JSONObject doInBackground(String... urls) {
try {
URL url = new URL(urlWithoutKartNum.replace("#kart_num#", kartNumber););//**-->how to include kart number there in url**
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
..........
..........
}
或者您可以直接将其添加为:
"http://race.speedtiming.com/api/index.php/races/scoreboard.json?track_id="+ kartNmber;
答案 1 :(得分:0)
只需将editText
值添加到网址,如下所示:
int kartNumber = Integer.parseInt(etGokart.getText().toString());
.......
.......
protected JSONObject doInBackground(String... urls) {
try {
URL url = new URL("http://race.speedtiming.com/api/index.php/races/scoreboard.json?track_id="+kartNumber);//**-->how to include kart number there in url**
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
..........
..........
}
答案 2 :(得分:0)
firefox_binary.py