2017-06-26 12 views
0

**このコードは、別のJavaファイルディスプレイのトーストメッセージそれは、テキスト私はコードを使用しましたが、その結果はトーストメッセージのために来ています。私はテキストビューのためにそれを望みます。

のために誰かしてください以下のJavaコードからテキストコード**

https://www.tutorialspoint.com/android/android_location_based_services.htm

は、これは私がコード

btnShowLocation =(ボタンを使用し、そこからのリンクであることができます)findViewById(R.id.button);

// show location button click event 
    btnShowLocation.setOnClickListener(new View.OnClickListener() { 

     private TextView textView; 
     @Override 
     public void onClick(View arg0) { 
      // create class object 
      gps = new GPSTracker(MapsActivity.this); 

      // check if GPS enabled 
      if(gps.canGetLocation()){ 

       double latitude = gps.getLatitude(); 
       double longitude = gps.getLongitude(); 

       // \n is for new line 
       Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " 
         + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show(); 
      }else{ 
       // can't get location 
       // GPS or Network is not enabled 
       // Ask user to enable GPS/network in settings 
       gps.showSettingsAlert(); 
      } 

     } 
+1

これで何をしたいですか? – Sanoop

答えて

0

あなたは

btnShowLocation = (Button) findViewById(R.id.button); 
    // show location button click event 
btnShowLocation.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View arg0) { 
     gps = new GPSTracker(MapsActivity.this); 

     // check if GPS enabled 
     if(gps.canGetLocation()){ 

      double latitude = gps.getLatitude(); 
      double longitude = gps.getLongitude(); 

      // set the text here 
      textView.setText("Your Location is - \nLat: " 
        + latitude + "\nLong: " + longitude); 
     }else{ 
      // can't get location 
      // GPS or Network is not enabled 
      // Ask user to enable GPS/network in settings 
      gps.showSettingsAlert(); 
     } 

    } 
0

を、次のように行うよう

private TextView textView = (TextView) findViewById(R.id.you_text_view_id); 

の下に、クリックリスナーであなたのテキストビューを初期化することができ、このコードを使用してToastを交換してください。

LinearLayout linearLayout = new LinearLayout(this); 
TextView YourTextView = new TextView(this); 

YourTextView.setText("Your Location is - \nLat: " 
        + latitude + "\nLong: " + longitude); 
linearLayout.addView(YourTextView); 
+0

大変お世話になりました、ありがとうございました。 –

+0

歓迎!親切に答えが受け入れられたらそれを受け入れてください:) –

関連する問題