Search code examples
javaandroidlocationmanager

Share two TextView with one Button


I have two textview and i want to merge two textview and when i click to share button send data latitude_textview and longitude_textview together, how I can do it?

For example,when i'm pressing to share button i want to get 21.00000, 21.00000 and share it.

        shareit = (Button) findViewById(R.id.shareit);
        mLatitudeTextView = (TextView) findViewById((R.id.latitude_textview));
        mLongitudeTextView = (TextView) findViewById((R.id.longitude_textview));

        //share location button
        shareit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                TextView msg = (TextView) findViewById(R.id.longitude_textview);
                String finalMsg = String.valueOf(msg.getText().toString().trim());
                intent.putExtra(Intent.EXTRA_TEXT, finalMsg);
                Intent modIntent = Intent.createChooser(intent, "Поделиться..");
                startActivity(modIntent);
            }
        });

Solution

  • I think you need to

        mLatitudeTextView = (TextView) findViewById((R.id.latitude_textview));
        mLongitudeTextView = (TextView) findViewById((R.id.longitude_textview));
    
        //share location button
        shareit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                String lat = mLatitudeTextView.getText().toString();
                String lng = mLongitudeTextView .getText().toString();
                String finalMsg = "Lat : " + lat + ", Lon : "+ lng;
                intent.putExtra(Intent.EXTRA_TEXT, finalMsg);
                Intent modIntent = Intent.createChooser(intent, "Поделиться..");
                startActivity(modIntent);
            }
        });
    

    You can look more here : Sending Simple Data