2012-01-03 3 views
0

Im new to android 및 위도 및 경도 정수를 텍스트 필드 안의 화면에 출력하는 프로그램을 만들려고합니다.은 android의 텍스트 필드에 인쇄 할 수 없습니다.

<EditText 
     android:id="@+id/longitudeField" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/latitudeField" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:inputType="text"/> 

내가 EmergencyLocation라는 클래스를 실행하는 자바 파일을 알고 :

필자는 두 개의 텍스트 필드를 편집 할 수 있습니다. 이 파일에서 경도와 위도를 설정하고 편집 텍스트 필드를 통해 화면에 출력하려고합니다.하지만 이렇게 할 때마다 아무 것도 나타나지 않습니다.

import android.app.Activity; 
import android.location.Location; 
import android.location.LocationListener; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.content.Context; 
import android.location.LocationManager; 
import android.location.Criteria; 

     public class EmergencyLocation extends Activity implements LocationListener 
     { 
      private TextView latitudeField; 
      private TextView longitudeField; 
      private LocationManager locationManager; 
      private String provider; 

      @Override 
      public void onCreate(Bundle savedInstanceState) 
      { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.main); 
       latitudeField = (TextView) findViewById(R.id.latitudeField); 
       //logitudeField = (TextView) findViewById(R.id.????); 

       locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

       Criteria criteria = new Criteria(); 
       provider = locationManager.getBestProvider(criteria, false); 
       locationManager.requestLocationUpdates(provider, 0, 0, this); 
       Location location = locationManager.getLastKnownLocation(provider); 
       onLocationChanged(location); 
      } 

      @Override 
      public void onDestroy() 
      { 
       super.onDestroy(); 
       locationManager.removeUpdates(this); 
      } 

      @Override 
      public void onLocationChanged(Location location) 
      { 
       if(location != null) 
       { 
        System.out.println("Provider " + provider + " has been selected."); 
        int lat = (int) (location.getLatitude()); 
        //int lng = (int) (location.getLongitude()); 
        latitudeField.setText(String.valueOf(lat)); 
        //longitudeField.setText(String.valueOf(lng)); 
       } 
       else 
       { 
        latitudeField.setText(String.valueOf("Provider not avaliable")); 
        //the same with long stuff 
       } 
      } 
      @Override 
      public void onProviderDisabled(String provider) { 
       // TODO Auto-generated method stub 

      } 
      @Override 
      public void onProviderEnabled(String provider) { 
       // TODO Auto-generated method stub 

      } 
      @Override 
      public void onStatusChanged(String provider, int status, 
        Bundle extras) { 
       // TODO Auto-generated method stub 

      } 
     } 

내가 전에 안드로이드에 새로운 메신저로 말했고 나는 그것이 매우 간단한 메신저 누락이라고 생각합니다.

+1

로깅 코드를 더 추가하면 응용 프로그램이 얼마나 멀리 떨어져 있는지 확인할 필요가 있습니다. 또한 발생할 수있는 문제를 최소화하기 위해 (예를 들어 developer.android.com 사이트에서) 실례를 ​​취하는 것이 좋습니다. – KevinDTimm

답변

0

귀하의 앱을 테스트했습니다. 작동 중이며 위치가 업데이트 중입니다. AndroidManifest.xml에 LOCATION-permisions을 지정하는 것을 잊어 버리시겠습니까? 여기 또한

:

provider = locationManager.getBestProvider(criteria, false); 

제공자는 null이 될 수 있습니다. 그래서

locationManager.requestLocationUpdates(provider, 0, 0, this); 

을하는 동안이 경우는 예외가 나타날 것입니다, 당신은 requestLocationUpdates()를 호출하기 전에 "널 (null)"에 대한 제공자를 확인해야합니다.

또한 경도에 문제가 있습니까?

+0

이 앱을 테스트했는데 성공 했습니까? 시험하기 위해 당신은 무엇을 사용 했습니까? 나는 안드로이드 폰이 없으며 Eclipse는 Long/Lat를 출력하지 않는 것 같다. – PurpleSmurph

+0

또한 매니페스트에 어떤 권한을 지정해야합니까? – PurpleSmurph

+0

나는 삼성 GT I5800 휴대 전화를 사용했다. 정확히 사용 권한은 [link] (http://developer.android.com/reference/android/Manifest.permission.html)에서 읽어야한다. 나는 이것을 AndroidManifest.xml에 두었습니다 : ** ** – Prizoff

0

getLatitude 실제로 더블을 반환 사전에

감사합니다. 너 그거 해봤 니?

+0

그래, 그래도 아무것도 나오지 않는다. 그래서 성가시다. 나는 그것을 볼 수없는 단순한 무언가 일 것임에 틀림 없다. – PurpleSmurph

+0

다른 방법을 무시하고 작동하는 제공 업체가 있는지 확인하십시오. – Snicolas

+0

더 많은 로그를 제공하십시오. 시스템을 꺼내 주나요? – Snicolas

관련 문제