0

www.zamboangatoday.ph からデータを収集し、すべてのニュース タイトルまたはヘッダーを取得する Android アプリを作成しています。しかし、誰かが私のコードをチェックできるアイテムは1つしか取得できません。

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



            try{

                outputTextView = (TextView)findViewById(R.id.textView1);
                //Document doc = Jsoup.parse(html,"http://www.zamboangatoday.ph");
                Document doc = Jsoup.connect("http://www.zamboangatoday.ph/").get();
                //Elements tag = doc.select(".even h4 a");

                Iterator<Element> iter = doc.select("li.even h4 a").iterator();
                //List<Image> images = new ArrayList<Image>();
                while(iter.hasNext())
                {
                    Element element = iter.next();

                    outputTextView.setText(element.text());

                }

            }catch(Exception e)
            {
                e.printStackTrace();
            }




    }
4

1 に答える 1

1

コンポーネントが何であるかはわかりませんoutputTextViewが、次のコードを使用します。

outputTextView.setText(element.text());

テキストを設定し、反復ごとに上書きします。したがって、ループの後、最後の要素のテキストのみが表示されます。可能であれば、次のようなものを使用してくださいoutputTextView.append(element.text());- そうでなければ a を使用してStringBuilder、ループの後にテキストを設定します。


outputTextView = (TextView)findViewById(R.id.textView1);
//Document doc = Jsoup.parse(html,"http://www.zamboangatoday.ph");
Document doc = Jsoup.connect("http://www.zamboangatoday.ph/").get();
//Elements tag = doc.select(".even h4 a");

Iterator<Element> iter = doc.select("li.even h4 a").iterator();
//List<Image> images = new ArrayList<Image>();
while(iter.hasNext())
{
    Element element = iter.next();

    /*
     * Append the text - don't overwrite it
     * Node: Maybe you have to add a new line ('\n').
     */
    outputTextView.append(element.text()); 

}
于 2013-01-07T15:57:06.283 に答える