Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SelectUni extends ListActivity {
- // URL to get contacts JSON
- private static String URL2 = "http://echo.jsontest.com/key/value/one/two";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getListView().setBackgroundColor(Color.rgb(255, 255, 255));
- try {
- Log.d("URL", new URL(URL2).toString());
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- try {
- new URL(URL2).openConnection().connect();
- } catch (IOException e) {
- e.printStackTrace();
- }
- //Log.d("TEST", getJSON(URL2));
- String[] test = {"sd", "nsdkh", "sdkjf", "!", "hjsbdf", "jksd", "skdhg", "hdvgb", "dmhsdf", "sjhfg", "jksd", "skdhg", "hdvgb", "dmhsdf", "sjhfg"};
- Arrays.sort(test);
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1, test);
- setListAdapter(adapter);
- }
- public static String getJSON(String url) {
- HttpsURLConnection con = null;
- try {
- URL u = new URL(url);
- con = (HttpsURLConnection) u.openConnection();
- con.connect();
- BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
- StringBuilder sb = new StringBuilder();
- String line;
- while ((line = br.readLine()) != null) {
- sb.append(line + "n");
- }
- br.close();
- return sb.toString();
- } catch (MalformedURLException ex) {
- ex.printStackTrace();
- } catch (IOException ex) {
- ex.printStackTrace();
- } finally {
- if (con != null) {
- try {
- con.disconnect();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement