在android中显示来自url的消息

发布于 2024-12-20 09:11:51 字数 76 浏览 3 评论 0原文

我需要在 Android 应用程序的文本视图中使用 URL 显示消息和名称。我该怎么办呢。请指导我示例代码/链接。

谢谢。

I need to display message and name using URL in Text view in android application. How can i do that. Please guide me a sample code/link.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您应该使用 AsyncTask 从指定的 URL 获取所需的数据,然后解析并显示它。

在这里阅读:http://developer.android.com/reference/android/ os/AsyncTask.html

You should use an AsyncTask to get the data you need from the specified URL and then parse it and show it.

Read about it here: http://developer.android.com/reference/android/os/AsyncTask.html

沫尐诺 2024-12-27 09:11:51

//你想要这样吗

if(!url_text.getText().toString().trim().equalsIgnoreCase("")){
                    textView.setText("");
                    HttpClient client = new DefaultHttpClient();
                    HttpGet request = new HttpGet(url_text.getText().toString());
                    // Get the response
                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                    String response_str = client.execute(request, responseHandler);
                    textView.setText(response_str);
                }else{
                    Toast.makeText(getApplicationContext(), "URL String empty.", Toast.LENGTH_LONG).show();
                }

//do u want like this

if(!url_text.getText().toString().trim().equalsIgnoreCase("")){
                    textView.setText("");
                    HttpClient client = new DefaultHttpClient();
                    HttpGet request = new HttpGet(url_text.getText().toString());
                    // Get the response
                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                    String response_str = client.execute(request, responseHandler);
                    textView.setText(response_str);
                }else{
                    Toast.makeText(getApplicationContext(), "URL String empty.", Toast.LENGTH_LONG).show();
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文