Search code examples
androidtextviewstringbuffer

Can't display all description.StringBuffer capacity?


I want to read an RSS feed on my app, i have been based on some guides, and i succeed to implement the basics. However, when i open an RSS item, the title is showen, but the description(that have more caracters) ends with some 13 lines and three points(...). I've read in JAVA doc that StringBuffer has a limited capacity, and when it arrives on its full capacity it sets a points. That why i think that the problem comes from StringBuffer:

    public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
            // Nous réinitialisons le buffer a chaque fois qu'il rencontre un item
            buffer = new StringBuffer();        

            // Ci dessous, localName contient le nom du tag rencontré

            // Nous avons rencontré un tag ITEM, il faut donc instancier un nouveau feed
            if (localName.equalsIgnoreCase(ITEM)){          
                this.currentFeed = new Feed();
                inItem = true;
            }

            // Vous pouvez définir des actions à effectuer pour chaque item rencontré
            if (localName.equalsIgnoreCase(TITLE)){
                // Nothing to do    
            }
            if (localName.equalsIgnoreCase(LINK)){
                // Nothing to do    
            }
            if (localName.equalsIgnoreCase(PUBDATE)){   
                // Nothing to do    
            }
            if (localName.equalsIgnoreCase(CREATOR)){
                // Nothing to do
            }
            if(localName.equalsIgnoreCase(DESCRIPTION)){

            }
        }

@Override
    public void endElement(String uri, String localName, String name) throws SAXException {     

        if (localName.equalsIgnoreCase(TITLE)){
            if(inItem){             
                // Les caractères sont dans l'objet buffer
                this.currentFeed.setTitle(buffer.toString());               
                buffer = null;
            }
        }
        if (localName.equalsIgnoreCase(LINK)){
            if(inItem){             
                this.currentFeed.setLink(buffer.toString());                
                buffer = null;
            }
        }
        if (localName.equalsIgnoreCase(PUBDATE)){   
            if(inItem){             
                this.currentFeed.setPubDate(buffer.toString());             
                buffer = null;
            }
        }
        if (localName.equalsIgnoreCase(CREATOR)){
            if(inItem){             
                this.currentFeed.setCreator(buffer.toString());             
                buffer = null;  
            }
        }
        if(localName.equalsIgnoreCase(DESCRIPTION)){
            if(inItem){             
                this.currentFeed.setDescription(buffer.toString());             
                buffer = null;
            }
        }
        if (localName.equalsIgnoreCase(ITEM)){      
            feeds.add(currentFeed);
            inItem = false;
        }
    }

    // * Tout ce qui est dans l'arborescence mais n'est pas partie  
    // * intégrante d'un tag, déclenche la levée de cet événement.  
    // * En général, cet événement est donc levé tout simplement 
    // * par la présence de texte entre la balise d'ouverture et 
    // * la balise de fermeture

    public void characters(char[] ch,int start, int length) throws SAXException{        
        String lecture = new String(ch,start,length);
        if(buffer != null) buffer.append(lecture);              
    }


    // cette méthode nous permettra de récupérer les données
    public ArrayList<Feed> getData(){
        return feeds;
    }
}

Any help please? Thank you very much.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  >
    <TextView android:text="" android:id="@+id/tv_title" android:layout_gravity="center_horizontal" android:layout_height="50dp" android:layout_width="fill_parent"/>
    <TextView android:text="" android:id="@+id/tv_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp"/>
    <TextView android:text="" android:id="@+id/tv_date" android:layout_marginTop="30dp" android:layout_height="fill_parent" android:layout_width="fill_parent"/>
</LinearLayout>

Solution

  • No, StringBuffer has no such behavior. You're probably using a TextView and have the ellipsize attribute set or your feed data actually is truncated and ellipsized itself. Take a look at the RSS feed directly in a browser to see if it is.