1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
package com.Webynux.net;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class Webynuxnet extends Activity {
public static RssItem selectedRssItem = null;
String feedUrl = "http://www.webynux.net/feed";
ListView rssListView = null;
ArrayAdapter<RssItem> aa = null;
ArrayList<RssItem> rssItems = RssItem.getRssItems(feedUrl);
public static final int RssItemDialog = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get the listview from layout.xml
rssListView = (ListView) findViewById(R.id.rssListView);
// here we specify what to execute when individual list items clicked
rssListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View view, int index, long arg3) {
selectedRssItem = rssItems.get(index);
tout d'abord, je suppose que je dois remplacer ce bloc par la webview ici, c'est bien cela ?
dois je declarer la webview dans un des fichiers xml ?
// we call the other activity that shows a single rss item in one page
Intent intent = new Intent("Webynuxnet.displayRssItem");
startActivity(intent);
}
});
aa = new ArrayAdapter<RssItem>(this, R.layout.list_item, rssItems);
rssListView.setAdapter(aa);
refressRssList();
}
protected Dialog onCreateDialog(int id, Bundle args) {
// TODO Auto-generated method stub
switch (id) {
case RssItemDialog: {
LayoutInflater li = LayoutInflater.from(this);
View rssDetails = li.inflate(R.layout.rss_details, null);
AlertDialog.Builder rssDialog = new AlertDialog.Builder(this);
rssDialog.setTitle("Article Webynux.net");
rssDialog.setView(rssDetails);
return rssDialog.create();
}
}
return null;
}
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
// TODO Auto-generated method stub
switch (id) {
case RssItemDialog: {
AlertDialog rssDialog = (AlertDialog) dialog;
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd - hh:mm:ss");
rssDialog.setTitle(selectedRssItem.getTitle() + " : " + sdf.format(selectedRssItem.getPubDate()));
String text = selectedRssItem.getDescription() + " : " + selectedRssItem.getLink();
TextView tv = (TextView) rssDialog.findViewById(R.id.rssDetailsTextView);
tv.setText(text);
}
}
}
private void refressRssList() {
ArrayList<RssItem> newItems = RssItem.getRssItems(feedUrl);
rssItems.clear();
rssItems.addAll(newItems);
aa.notifyDataSetChanged();
}
} |