Now, I have made a code prototype in java which is the following:
URL url = new URL("http://gobettivolta.gov.it/");
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
String sottostringa = null;
while ((line = br.readLine()) != null) {
if(line.contains("[Circ")){
line = line.trim();
if(line.contains("\t"))
line = line.substring(0, line.indexOf("\t"));
if(line.contains("<"))
line = line.substring(0, line.indexOf("<"));
System.out.println(line);
}
}
I think it's pretty straight forward, I just want to get the titles of the articles and print them out in the terminal. Everything works just fine in NetBeans but then I wanted to transfer every title in a list view in android.
I've already prepared the bone structure, so I've got a list view where there's everything I need; I've tried to populate it with examples put in a listArray and everything works there as well.
The thing is putting them two things together, I'd like to place every title in the listArray of the application and show them in the list view.
I've tried to copy the code right away in android studio but nothing shows up other than an example string I placed before the loop.
I've also tried to place another string after the loop and that doesn't show up either. So the cases are two: either the program stops inside the loop or the loop takes forever to end..
The thing is I haven't written anything down in the manifest.. should I do something there?? Or is there something it's not permitted to do in android that I did??
And also, I know I could have used parsing libraries, but considered the easiness of the task I thought it would have been just a waste; so I wrote what I needed by my own..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listaCircolari = new ArrayList<Circolare>();
try {
riempiCircolari();
} catch(Exception e){}
ListAdapter adapter = new ListAdapterCircolari(MainActivity.this, listaCircolari);
ListView list = (ListView) findViewById(R.id.list_view_circolari);
list.setAdapter(adapter);
}
private void riempiCircolari() throws Exception{
listaCircolari.add(new Circolare("Pluto"));
URL url = new URL("http://gobettivolta.gov.it/");
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
String sottostringa = null;
while ((line = br.readLine()) != null) {
if(line.contains("[Circ")){
line = line.trim();
if(line.contains("\t"))
line = line.substring(0, line.indexOf("\t"));
if(line.contains("<"))
line = line.substring(0, line.indexOf("<"));
listaCircolari.add(new Circolare(line));
}
}
listaCircolari.add(new Circolare("pippo"));
}
The list adapter works fine and all the rest do I'd avoid putting them here.