TextView中被切断了大量的信息,当我尝试从一个网站发送文本 [英] TextView is cutting off a lot of information when I try to pull text from a website

查看:192
本文介绍了TextView中被切断了大量的信息,当我尝试从一个网站发送文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我需要从该网站发送文本。
http://www.cellphonesolutions.net/help-en-lite

请注意如何它是一个非常大的文件。当我尝试拉文本不获取文本的前半部分。是否有字符的TextView的可容纳量的限制吗?如果是的话我怎么去解决这个问题。这里是code我用收集的文字。

//在onCreate方法

  TextView的常见问题解答=(的TextView)findViewById(R.id.tvfaq);
    faq.setText((Html.fromHtml(
            cleanhtml(的getText(http://www.cellphonesolutions.net/help-en-lite)
            )));

这清除了评论指出Html.fromHtml不会过滤掉

 公共字符串cleanhtml(原字符串){
    串finalText = original.replaceAll(&下;![^]的计算值*>中,);    返回finalText;
}

这是我如何才能从网站上的文字

 公共字符串的getText(字符串URI){
    HttpClient的客户端1 =新DefaultHttpClient();
    HTTPGET请求=新HTTPGET(URI);    ResponseHandler所<串GT; ResponseHandler所=新BasicResponseHandler();
    尝试{
        字符串response_str = client1.execute(请求,ResponseHandler所);
        返回response_str;    }赶上(例外五){
        // TODO自动生成catch块
        e.printStackTrace();
        返回;    }
}

下面是我的XML

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout的android:背景=@绘制/ splash_fade
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直的android:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    <滚动型机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT>
    < TextView的机器人:layout_gravity =中心的android:文本=TextView的机器人:比重=中心
        机器人:ID =@ + ID / tvfaq的android:layout_width =WRAP_CONTENT机器人:文字颜色=#000000
        机器人:layout_height =WRAP_CONTENT>< / TextView的>
< /滚动型>
< / LinearLayout中>


解决方案

试着删除滚动型

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout的android:背景=@绘制/ splash_fade
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直的android:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    < TextView的机器人:layout_gravity =中心的android:文本=TextView的机器人:比重=中心
        机器人:ID =@ + ID / tvfaq的android:layout_width =WRAP_CONTENT机器人:文字颜色=#000000
        机器人:layout_height =WRAP_CONTENT>< / TextView的>
< / LinearLayout中>

TextView中有一个Implemeted一个滚轮会做你希望用什么滚动视图

更新

您需要适用于您的TextView faq.setMovementMethod(新ScrollingMovementMethod());

如果不行尝试调试应用程序,看看是否有response_str所有字符从网站

In my app I need to pull text from this website. http://www.cellphonesolutions.net/help-en-lite

Notice how its a very large file. When I try to pull the text it doesn't get the first half of the text. Is there a limit to the amount of characters a textview can hold? if so how do I go around this problem. Here is the code I use to gather the text.

//in the oncreate method

    TextView faq = (TextView) findViewById(R.id.tvfaq);
    faq.setText((Html.fromHtml(
            cleanhtml(getText("http://www.cellphonesolutions.net/help-en-lite)
            )));

This clears up the comments that Html.fromHtml doesn't filter out

public String cleanhtml(String original) {
    String finalText = original.replaceAll("<![^>]*>", "");

    return finalText;
}

This is how I get the text from the website

public String getText(String uri) {
    HttpClient client1 = new DefaultHttpClient();
    HttpGet request = new HttpGet(uri);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        String response_str = client1.execute(request, responseHandler);
        return response_str;

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";

    }
}

Here is my xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:background="@drawable/splash_fade"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
    <TextView android:layout_gravity="center" android:text="TextView" android:gravity="center"
        android:id="@+id/tvfaq" android:layout_width="wrap_content" android:textColor="#000000"
        android:layout_height="wrap_content"></TextView>
</ScrollView>
</LinearLayout>

解决方案

Try to remove the ScrollView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:background="@drawable/splash_fade"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_gravity="center" android:text="TextView" android:gravity="center"
        android:id="@+id/tvfaq" android:layout_width="wrap_content" android:textColor="#000000"
        android:layout_height="wrap_content"></TextView>
</LinearLayout>

TextView has an implemeted scroller that will do what you expect with a scrollview.

UPDATE

you need to apply that to your textView faq.setMovementMethod(new ScrollingMovementMethod());

If that doesn't work try to debug your application and see if response_str has all the characters from the website

这篇关于TextView中被切断了大量的信息,当我尝试从一个网站发送文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆