2010-10-26 83 views
-1

我已經編寫了地理編碼代碼..但不幸的是它不起作用,即屏幕上沒有顯示任何東西......我附上代碼.. 。可有人告訴我什麼是在code..thanks因爲你不告訴任何顯示在屏幕上被顯示在屏幕上android geocoder ---當我運行應用程序時,屏幕上沒有任何顯示

public class geocoder extends Activity { 

// private TextView output; 
private LocationManager mgr; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     mgr = (LocationManager) getSystemService(LOCATION_SERVICE); 

     Geocoder geocoder = new Geocoder(this, Locale.US); 
     // output = (TextView) findViewById(R.id.output); 
     String staddress = "Georgia Tech, Atlanta, GA"; 
     // List<Address> loc = null; 
     try{ 
     List<Address> loc = geocoder.getFromLocationName(staddress, 5); 
     } 
     catch(IOException e) { 
     Log.e("IOException", e.getMessage()); 

     } 
     // output = (TextView) findViewById(R.id.output); 
    } 
} 

回答

2

沒有什麼過錯。

您將地理編碼結果存儲在變量loc中,然後不做任何處理。

調用findViewById(R.id.output)是正確的;你需要用你想看到的東西來實際更新TextView

例如作爲一個超基本的I-haven't-read-the-Address-Javadoc示例:

// Do some geocoding 
List<Address> loc = geocoder.getFromLocationName(staddress, 5); 

// Find the 'output' TextView defined in main.xml 
TextView info = (TextView) findViewById(R.id.output); 

// Show the first geocoded result in the 'output' TextView 
info.setText("Address: "+ loc.get(0).toString()); 
相關問題