2016-10-27 3 views
0

나는 (학습) 테스트 응용 프로그램을 개발하고 있어요는공유 텍스트 만 안드로이드 스튜디오

위치 코드 ... 등을 이메일을 통해 공유 할 수 매우 잘 작동하지만 전자 메일 인터페이스가 호출되면 다음과 같이 많은 코드가 함께 제공됩니다.

"Android.widget.TextView {f05b211V.ED .... ..ID 48,108-1032, 165 # 7f0d0053 applied/tv_coordinate} "

어떻게 해결할 수 있습니까? 올바른 값 (위도와 경도, 경우) 만 표시됩니까?

감사합니다.

public class MainActivity extends ActionBarActivity 
    implements GoogleApiClient.ConnectionCallbacks, 
    GoogleApiClient.OnConnectionFailedListener { 

private TextView tvCoordinate; 
private GoogleApiClient mGoogleApiClient; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    tvCoordinate = (TextView) findViewById(R.id.tv_coordinate); 

    callConnection(); 
} 


private synchronized void callConnection() { 
    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .addOnConnectionFailedListener(this) 
      .addConnectionCallbacks(this) 
      .addApi(LocationServices.API) 
      .build(); 
    mGoogleApiClient.connect(); 


} 

String msg4; 



@Override 
public void onConnected(Bundle bundle) { 

    TextView resultado = (TextView) findViewById(R.id.result); 



    Log.i("LOG", "onConnected(" + bundle + ")"); 

    Location l = LocationServices 
      .FusedLocationApi 
      .getLastLocation(mGoogleApiClient); 

    if (l != null) { 
     Log.i("LOG", "latitude: " + l.getLatitude()); 
     Log.i("LOG", "longitude: " + l.getLongitude()); 
     tvCoordinate.setText(l.getLatitude() + " | " + l.getLongitude()); 

     msg4 = String.format("%s", tvCoordinate); 
     resultado.setText(msg4); 
    } 
} 

@Override 
public void onConnectionSuspended(int i) { 
    Log.i("LOG", "onConnectionSuspended(" + i + ")"); 
} 

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    Log.i("LOG", "onConnectionFailed(" + connectionResult + ")"); 
} 



public void enviardados(View view) { 
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
    sharingIntent.setType("text/plain"); 
    String shareBody = String.format("A localizacao e %s", msg4); 
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Localizacao"); 
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); 
    startActivity(Intent.createChooser(sharingIntent, "Compartilhar via")); 
} 

}

+0

* 이해 할 수없는 나는 *와 함께 오는 많은 코드가있다. Pls 정교. – Raghunandan

답변

2

 msg4 = String.format("%s", tvCoordinate.getText().toString()); 
+0

고마워! 이것은 효과가있다! – Vladimir

1

msg4 = String.format("%s", tvCoordinate);

가 텍스트를 넣어하려고 수행 텍스트 뷰에서 문자열이 아니라 그 객체를 얻을 다음과 같이

내 코드입니다 위 코드에서 msg4로 tvCoordinate 하시겠습니까? 예, 해당 코드를 변경하려고하면

:

msg4 = tvCoordinate.getText().toString();

관련 문제