Example #1
0
  @Override
  protected void onResume() {
    super.onResume();
    Connectivity.checkNet(BargeList.this);
    Log.d("333333333", "list is listening again");
    Connectivity.LOST_CONN = 0; // doubtful about this

    timer = new Timer(); // This can be made into a separate class.
    timer.scheduleAtFixedRate(
        new TimerTask() {

          @Override
          public void run() {
            FetchParse fp = new FetchParse();
            try {
              fp.fetch();
              bargeNames.clear();
              bargeStatus.clear();
              bargeTimes.clear();
              latList.clear();
              lonList.clear();
              for (int z = 0; z < fp.namelist.size(); z++) {
                bargeNames.add(fp.namelist.get(z));
                bargeStatus.add(fp.statlist.get(z));
                bargeTimes.add(fp.timelist.get(z));
                latList.add(fp.latlist.get(z));
                lonList.add(fp.lonlist.get(z));
                Log.d("3333333", "added barge");
              }
              handler.post(
                  new Runnable() {

                    @Override
                    public void run() {
                      Log.d("3333333", "inside the runnable");
                      bargeList = getListView();
                      bargeList.requestFocus();

                      bargeList.setOnItemClickListener(
                          new OnItemClickListener() {

                            @Override
                            public void onItemClick(
                                AdapterView<?> parent, View view, int position, long id) {
                              Log.d("33333333", "inside on click of list");
                              toBargeMap.putExtra("name", bargeNames.get(position));
                              toBargeMap.putExtra("status", bargeStatus.get(position));
                              toBargeMap.putExtra("lat", latList.get(position));
                              toBargeMap.putExtra("lon", lonList.get(position));
                              startActivity(toBargeMap);
                            }
                          });
                      myadapter =
                          new BargeArrayAdapter(
                              BargeList.this, getModel(1), getModel(2), getModel(3));
                      setListAdapter(myadapter);
                    }
                  });
            } catch (IOException e) {
              e.printStackTrace();
            } catch (JSONException e) {
              e.printStackTrace();
            }
          }
        },
        1000,
        10000); // refresh every 10 seconds
  }
Example #2
0
 @Override
 protected void onPause() {
   super.onPause();
   Connectivity.stopListeningToConn(BargeList.this);
   timer.cancel();
 }