解析された値を取得するプログラムに動的 ListView を実装しようとしています。今、ループの助けを借りて、それらの解析された値をその ListView に追加したいのですが、ここでは無力です。私は非常に多くの例を試しましたが失敗したので、誰か助けてください。私は本当に助けが必要だからです。ここにコードがあります。
package com.ifahja.cricketpredictor;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class ScorecardActivity extends Activity
{
ListView listView;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.scorecard);
ScorecardGetterSetter scorecard;
listView=(ListView)findViewById(R.id.listView1);
try
{
URL url;
String queryString1 ="http://static.cricinfo.com/rss/livescores.xml";
/* Replace blanks with HTML-Equivalent. */
url = new URL(queryString1.replace(" ", "%20"));
/* Get a SAXParser from the SAXPArserFactory. */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
/* Get the XMLReader of the SAXParser we created. */
XMLReader xr = sp.getXMLReader();
ScorecardHandler myHandler = new ScorecardHandler();
xr.setContentHandler(myHandler);
/* Parse the xml-data our URL-call returned. */
xr.parse(new InputSource(url.openStream()));
Log.d("URL", "it's all right");
}
catch (Exception e)
{
System.out.println(e);
Log.d("URL", "problum in URL");
}
scorecard = ScorecardHandler.scorecard;
//for(int i=1;i<scorecard.getTitle().size();i++)
//{
//TextView title = new TextView(this);
final String android_versions[] = {
scorecard.getTitle().get(1),
scorecard.getTitle().get(2),
scorecard.getTitle().get(3),
scorecard.getTitle().get(4),
scorecard.getTitle().get(5),
scorecard.getTitle().get(6),
// scorecard.getTitle().get(7),
// scorecard.getTitle().get(8),
// scorecard.getTitle().get(9),
// scorecard.getTitle().get(10),
// scorecard.getTitle().get(11),
`enter code here`// scorecard.getTitle().get(12),
// scorecard.getTitle().get(13),
// scorecard.getTitle().get(14),
// scorecard.getTitle().get(15),
// scorecard.getTitle().get(16),
// scorecard.getTitle().get(17),
// scorecard.getTitle().get(18),
// scorecard.getTitle().get(19),
};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.custom_list_item,android_versions);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
if(android_versions[arg2]==android_versions[0])
{
Intent intentList_0 = new Intent(ScorecardActivity.this,List_0.class);
startActivity(intentList_0);
}
}
});
}
}