如何通过http在android中的TextView中显示值

时间:2014-11-13 20:16:29

标签: android

我想显示我的数据库中的lat和lng的值当条件为真时它只返回1或0 plz给我一个在textview中显示lat和lng的多个值的解决方案

     here is my code:


   public class Map extends Activity implements OnClickListener  {
             TextView Test;

         public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maptest);

        status();

               }
     public void status() {
    int locationCount =locationCount() ;
    for(int i=0;i<locationCount;i++)
    {
     double Latt = Lat();
     double Lngg = Lng();

     Test=(TextView)findViewById(R.id.test);
     String lat = new Double(Latt).toString();
     String lng = new Double(Lngg).toString();
     Test.setText(lng+ lat);
    }

}


 public static String convertStreamToString(InputStream is) 
    {
     BufferedReader reader = new BufferedReader(new InputStreamReader(is));
     StringBuilder sb = new StringBuilder();

     String line = null;
     try {
      while ((line = reader.readLine()) != null) {
       sb.append(line + "\n");
      }
     } 
     catch (IOException e) {
      e.printStackTrace();
     } 
     finally {
      try {
       is.close();
      } catch (IOException e) {
    e.printStackTrace();
      }
     }
     return sb.toString();
    }

      public static double Lng()
        {
    try
    {
        DefaultHttpClient httpClient=new DefaultHttpClient();

        //Connect to the server
        HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/Lng");
      //Get the response
      HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
         InputStream stream=httpEntity.getContent();

         //Convert the stream to readable format
            String result= convertStreamToString(stream);

            if(result.charAt(1)=='1')
            {
             return 1;
            }
            else
            {
             return 0;
            }
     }
     catch(Exception e)
     {
      return 0;
     }

    }
     public static double Lat()
       {
    try
    {
        DefaultHttpClient httpClient=new DefaultHttpClient();

        //Connect to the server
        HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/Lat");
      //Get the response
      HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
         InputStream stream=httpEntity.getContent();

         //Convert the stream to readable format
            String result= convertStreamToString(stream);

            if(result.charAt(1)=='1')
            {
             return 1;
            }
            else
            {
             return 0;
            }
     }
     catch(Exception e)
     {
      return 0;
     }

    }

    public static int locationCount()
    {
    try
    {
        DefaultHttpClient httpClient=new DefaultHttpClient();

        //Connect to the server
        HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/locationCount");
      //Get the response
      HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
         InputStream stream=httpEntity.getContent();

         //Convert the stream to readable format
            String result= convertStreamToString(stream);

            if(result.charAt(1)=='1')
            {
             return 1;
            }
            else
            {
             return 0;
            }
     }
     catch(Exception e)
     {
      return 0;
     }

    }

   }

我想显示我的数据库中的lat和lng的值当条件为真时它只返回1或0 plz给我一个在textview中显示lat和lng的多个值的解决方案

 Thank you so much in advance :( 

0 个答案:

没有答案