2

こんにちは、アプリに問題があります。Android 2.2 以下の新しいプロジェクトを作成すると、アプリは正常に動作し、トーストが画面に表示されますが、同じコードで 2.3 または 2.3.3 の新しいプロジェクトを作成すると、トーストがまったく表示されません。また、メインの 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());

        }
    }
4

1 に答える 1

3

Toast で show() を呼び出す必要があります。

Toast.makeText(context, Text, duration).show();

あなたがしているのは、Toast を作成することだけであり、それを表示することはありません。

例外が原因で、TextView の更新が失敗している可能性があります。

于 2011-03-17T17:19:33.410 に答える