2

What Im trying to achieve is display points on a map using postcode. I found a script that does this for one postcode, but I would like to display a few at once. So I was thinking of changing the code around a little so the map was created in the first class.

My question is, how do I transfer the values of Class B to Class A? 2 values 'lng' and 'lat' need to be an array

My full code is here if that makes more sense http://pastebin.com/L6tcuPW9

Any help would be great

   Class A extents FragmentActivity
   {

   }

This class gets retrieves the lng and lat values

    Class B
    {
        public static double[]      lat;
        public static double[]      lng;

        public void retrievePost( String post)
        {
             // does a search and retrieves lng and lat

             setLat(lat); 
             setLng(lng); 
        }

        public static void setLat(double lat2)
        {
        // How do I get this value back into Class A

        }

        public static void setLng(double lng2)
        {
        // How do I get this value back into Class A

        }
    }
  • you can achieve this things by creating an interface so that you can implement it in your Class A and get the updated value. – Rajan Feb 01 '14 at 10:50
  • Care to explain a little more? For the life of me I cant think how to do it – user3237406 Feb 01 '14 at 11:04

1 Answers1

1

Try this:

public interface MyInterface {
    public void setLat(double lat);
    public void setLng(double lng);
}


class A extends FragmentActivity implements MyInterface{
    @Overwrite
    public void setLat(double lat) {
            //Do Something
    }
    @Overwrite
    public void setLng(double lng){
            //Do Something
    }
 }


 Class B
 {
      private MyInterface interface;
      public B(MyInterface interface){
           this.interface = interface;
      }
      public void retrievePost( String post){
           interface.setLat(lat); 
           interface.setLng(lng); 
      }
 }    
Stephan
  • 15,704
  • 7
  • 48
  • 63
  • Thanks, I'll have a crack at it – user3237406 Feb 01 '14 at 11:17
  • Hmm right Ive been having a play but I'm no closer :( class ParserTask extends AsyncTask>> I use that to get the Lng and Lat. These are the values I need in my first class. How do I implement into an AsyncTask? – user3237406 Feb 01 '14 at 12:23
  • Same as shown in my answer: class B is your asynctask and in onPostExecute() you call interface.setLat(). You need to provide an instance of your class A by calling the constructor of your AsyncTask. – Stephan Feb 01 '14 at 12:34
  • I give up! Its coming up with Invalid Variable Declaration when I add that stuff in the Asyntack class – user3237406 Feb 01 '14 at 14:12
  • Maybe you should ask a new question with your specific problems. – Stephan Feb 01 '14 at 15:55