android geocoder ---当我运行应用程序时,屏幕上不显示任何内容

时间:2010-10-26 21:01:32

标签: android eclipse

我已经编写了地理编码的代码..但遗憾的是它无法正常工作,即屏幕上没有显示任何内容...我正在附加代码...有人可以告诉我代码中的错误是什么。谢谢

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);
    }
}

1 个答案:

答案 0 :(得分:2)

屏幕上没有显示任何内容,因为您没有在屏幕上显示任何内容。

您将地理编码结果存储在变量loc中,然后对其执行任何操作。

致电findViewById(R.id.output)是正确的;您需要使用您想要查看的内容实际更新TextView

e.g。作为一个超级基本的I-yet-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());
相关问题