如何在吐司中显示html / php代码

时间:2015-02-10 12:06:21

标签: java php android toast

我从php文件读取数据放入数组。我希望在吐司中显示描述但吐司显示html / php标签。我怎么能删除它?

News.java

public class News {

    int information_id;
    int language_id;
    String title;
    String description;

    public int getinformation_id() {
        return information_id;
    }

    public int getlanguage_id() {
        return language_id;
    }

    public String gettitle() {
        return title;
    }

    public String getdescription() {
        return description;
    }

    public void setinformation_id(int information_id) {
        this.information_id = information_id;
    }

    public void setlanguage_id(int language_id) {
        this.language_id = language_id;
    }

    public void settitle(String title) {
        this.title = title;
    }

    public void setdescription(String description) {
        this.description = description;
    }

}

Main.java

ArrayList<News> news;
public ArrayList<String> infoid, lanid, titlenews, desnews; 
JSONObject json_data;
JSONArray jArray;

private void get_news() {

    try {
        url = "http://www.learnroid.ir/bigshop/get_news.php";

        dbGetData = new DbGetData();
        new Thread(new Runnable() {
            public void run() {
                data = dbGetData.getDataFromDB(url);

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        news = parseJSON(data);
                    }
                });
            }
        }).start();

        Toast.makeText(context, "Please wait ....", 5000).show();
    } catch (Exception e) {

    }
}

public ArrayList<News> parseJSON(String result) {
    news = new ArrayList<News>();

    try {
        jArray = new JSONArray(result);
        for (int i = 0; i < jArray.length(); i++) {
            json_data = jArray.getJSONObject(i);
            n = new News();

            information_id = json_data.getString("information_id");
            language_id = json_data.getString("language_id");
            title = json_data.getString("title");
            description = json_data.getString("description");

            n.setinformation_id(Integer.parseInt(information_id));
            n.setlanguage_id(Integer.parseInt(language_id));
            n.settitle(title);
            n.setdescription(description);

            infoid.add(information_id);
            lanid.add(language_id);
            titlenews.add(title);
            desnews.add(description);

            news.add(n);

            /*  int information_id;
            int language_id;
            String title;
            String description;*/
        }
        showdata();

        size = infoid.size();
        Toast.makeText(context, String.valueOf(size), Toast.LENGTH_SHORT).show();

    } catch (JSONException e) {
    }
    return news;
}

//从php获取数据并放入数组列表infoid,lanid,.............

我创建了一个从数组

显示数据的函数
    private void showdata() {

        Object[] Arraydes = desnews.toArray();
        Object[] Arraylan = lanid.toArray();

        for(int i = 0; i < Arraydes.length ; i++){
            String s = Arraylan[i].toString();
            if (s.equals("2")) {
      Toast.makeText(context, String.valueOf(Arraydes[i]),Toast.LENGTH_LONG).show();

            }
        }

数据表格表是:

information_id:6 language_id:1 标题:热点新闻 描述:&lt; p&gt;交货信息&lt; / p&gt;

但我只需要在Toast中显示

的送货信息

我的吐司文字是“&lt; p&gt;送货信息&lt; / p&amp; gt”

1 个答案:

答案 0 :(得分:0)

你可以创建一个去除html标签的功能,例如:

public String stripHtml(String html) {
    return Html.fromHtml(html).toString();
}

在toast中输出返回的字符串