您好,我将直截了当,我正在尝试使用 EditText 输入在 php url 中使用我希望 url 在运行时像 thi 一样。
http://www.free-map.org.uk/course/mad/ws/hits.php?artist=Oasis
所以我试过了
URL url = new URL("http://www.free-map.org.uk/course/mad/ws/hits.php?artist=",et1);
但我得到了错误
这是我的代码的主要部分。
class MyTask extends AsyncTask<Void,Void,String>
{
EditText et1 = (EditText)findViewById(R.id.et1);
public String doInBackground(Void... unused)
{
HttpURLConnection conn = null;
try
{
URL url = new URL("http://www.free-map.org.uk/course/mad/ws/hits.php?artist=",et1);
conn = (HttpURLConnection) url.openConnection();
InputStream in = conn.getInputStream();
if(conn.getResponseCode() == 200)
{
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String result = "", line;
while((line = br.readLine()) !=null)
result += line;
return result;
}
else
return "HTTP ERROR: " + conn.getResponseCode();
}
catch(IOException e)
{
return e.toString();
}
finally
{
if(conn!=null)
conn.disconnect();
}
}
你不能追加EditText
有String
。您必须从EditText
.
从EditText
使用中获取输入-
EditText et1 = (EditText)findViewById(R.id.et1);
final String input = et1.getText().toString();
// then append it
URL url = new URL("http://www.free-map.org.uk/course/mad/ws/hits.php?artist="+input);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句