【问题标题】:Android application connecting databaseAndroid应用连接数据库
【发布时间】:2015-05-08 07:22:52
【问题描述】:

我想在将通过应用程序输入的数据与数据库进行比较时显示成功或失败。比较代码在 php 中完成,我必须显示 php 返回的字符串。但是在执行以下代码时,一些 html 文件是显示为 toast。请帮助我

InputStream is = null;
            try {
                is = response.getEntity().getContent();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            final String responseMsg2 = convertStreamToString(is);
             runOnUiThread(new Runnable(){

                  @Override
                  public void run(){
                    //update ui here

                Toast.makeText(getApplicationContext(),responseMsg2,Toast.LENGTH_LONG).show();
                  }
               });

【问题讨论】:

  • 您是否在浏览器中查看过您的回复?获取 html 页面的原因有很多。

标签: php android wamp


【解决方案1】:

当您使用response.getEntity().getContent(); 时,您会以字符串形式获得整个响应(包括标签等)。所以你需要这样做:

String responseMsg2 = convertStreamToString(is);
final String responseAsText = android.text.Html.fromHtml(responseMsg2).toString();

然后在 Toast 中使用不带 html 标记的文本:

Toast.makeText(getApplicationContext(),responseAsText,Toast.LENGTH_LONG).show();

【讨论】:

    猜你喜欢
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 2012-04-23
    • 2011-07-28
    • 2015-03-16
    • 1970-01-01
    相关资源
    最近更新 更多