public void fillTable() { destinations = db.getAllDestinations(); for (Destination d : destinations) { TableRow tableRow = new TableRow(this); TextView nameText = new TextView(this); nameText.setText(d.getName()); tableRow.addView(nameText); TextView addressText = new TextView(this); addressText.setText(d.getAddress()); tableRow.addView(addressText); destinations_table.addView(tableRow); } TextView number = (TextView) findViewById(R.id.number_of_destinations_label); number.setText("# of destinations: " + destinations.size()); }
private String resolveDestination(String newDestination) { if (!newDestination.equals("")) { boolean exists = false; for (Destination d : destinations) { if (d.getAddress().equals(newDestination) || d.getName().equals(newDestination)) exists = true; } if (!exists) { // Do the resolver online from the BO HttpURLConnection connection; OutputStreamWriter request = null; URL url = null; String response = null; String parameters = "url=" + newDestination; try { url = new URL(postURL); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestMethod("POST"); request = new OutputStreamWriter(connection.getOutputStream()); request.write(parameters); request.flush(); request.close(); String line = ""; InputStreamReader isr = new InputStreamReader(connection.getInputStream()); BufferedReader reader = new BufferedReader(isr); StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) sb.append(line + "\n"); response = sb.toString(); System.out.println("Message from Server: " + response); isr.close(); reader.close(); if (response.contains("-1")) return null; else return response; } catch (IOException e) { e.printStackTrace(); return null; } /*InetAddress address = null; try { address = InetAddress.getByName(newDestination); } catch (UnknownHostException e) { e.printStackTrace(); } if (address != null) { String addressString = address.toString(); addressString = addressString.substring(addressString.indexOf("/") + 1, addressString.length()); return addressString; } */ } } return null; }