アプリでRSSフィードを読みたいのですが、いくつかのガイドに基づいており、基本を実装することに成功しています。ただし、RSSアイテムを開くと、タイトルは表示されますが、説明(文字数が多い)は13行と3ポイントで終わります(...)。私はJAVAdocで、StringBufferの容量が制限されていることを読みました。容量がいっぱいになると、ポイントが設定されます。そのため、問題は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;
}
}
何か助けてください?どうもありがとうございます。
<?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>