Rss フィードからデータを取得し、ListView
. 現在、タイトルを正常に解析し、ListView
. 問題は、アイテム(つまり、タイトル)をクリックしたときにListView
説明をロードする必要があることですが、それを解析する方法がわからないので、助けてください..
これは私の RssItem ページです:
public class RssItem {
// item title
private String title;
// item link
private String link;
private String description;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
@Override
public String toString() {
return title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
これは私の Rssparse ハンドラ ページです
public class RssParseHandler extends DefaultHandler {
private List<RssItem> rssItems;
// Used to reference item while parsing
private RssItem currentItem;
// Parsing title indicator
private boolean parsingTitle;
// Parsing link indicator
private boolean parsingLink;
public RssParseHandler() {
rssItems = new ArrayList<RssItem>();
}
public List<RssItem> getItems() {
return rssItems;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if ("item".equals(qName)) {
currentItem = new RssItem();
} else if ("title".equals(qName)) {
parsingTitle = true;
} else if ("link".equals(qName)) {
parsingLink = true;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("item".equals(qName)) {
rssItems.add(currentItem);
currentItem = null;
} else if ("title".equals(qName)) {
parsingTitle = false;
} else if ("link".equals(qName)) {
parsingLink = false;
} else if ("description".equals(qName)) {
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (parsingTitle) {
if (currentItem != null)
currentItem.setTitle(new String(ch, start, length));
} else if (parsingLink) {
if (currentItem != null) {
currentItem.setLink(new String(ch, start, length));
parsingLink = false;
}
}
}
}
このページは、項目をクリックすると説明が表示されます
public class Openpage extends Activity {
WebView wb=null;
String s1=null;
@SuppressLint({ "SetJavaScriptEnabled", "HandlerLeak" })
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newsfeed);
Intent i=getIntent();
s1=i.getStringExtra("link");
wb=(WebView)findViewById(R.id.webView1);
wb.loadUrl(s1);
wb.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress == 100){
// Page has fully loaded. Cancel the progress dialog here
}
}
});
}
class CustomWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
//do whatever you want with the url that is clicked inside the webview.
//for example tell the webview to load that url.
view.loadUrl(s1);
//return true if this method handled the link event
//or false otherwise
return true;
}
}
}