您好我的应用程序有问题。当我为Android 2.2或更低版本创建一个新项目时,我的应用程序工作正常,我的toast在屏幕上显示但是当我使用相同的代码创建2.3或2.3.3的新项目时,toast根本不会出现。此外,我在主OnCreate线程中添加了Textview更新,但我仍然没有更新textview。我主要是要解决吐司问题。 感谢
public class Location extends Activity {
/** Called when the activity is first created. */
static String Text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
final TextView tv = (TextView)findViewById(R.id.textView1);
lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
private final String TAG = null;
@Override
public void onLocationChanged(android.location.Location location) {
// TODO Auto-generated method stub
Text = "My current location is: " + "Latitud = " + location.getLatitude() + "Longitud = " + location.getLongitude();
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast.makeText(context, Text, duration).show();
tv.setText(Text);
try
{
File root = Environment.getExternalStorageDirectory();
File gps = new File(root, "log.txt");
BufferedWriter out = new BufferedWriter(
new FileWriter(gps,true)) ;
out.write(Text);
out.write("");
out.close();
}
catch (IOException e) {
Log.e(TAG, "Could not write file " + e.getMessage());
}
}
答案 0 :(得分:3)
你必须在Toast上调用show()。
Toast.makeText(context, Text, duration).show();
你所做的只是制作吐司而不是展示它。
由于异常,TextView更新可能会失败。