How to share data to whatsapp on click of linear layout?

Manoj Jangir 1 Reputation point
2021-04-24T18:49:18.563+00:00

Hello all,
I am new to xamarin forms and I am modifying a app and got stuck at a point and need your help. Actually I want to share data (image and text) on click of a linear layout directly to whatsapp. But I do not know how to implement the cross share function. There is already one function build and i just want to use that function to perform the task.
Here I am attaching the text file which have the code.

In the text file there is a function ShareOptionsLayoutOnClick(). I want to call this function on click of linear layout (i.e. ShareLinearLayout).90943-share.txt

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-04-27T07:16:44.25+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Just simply bind the Click event to the ShareOptionsLayoutOnClick method on LinearLayout .

    In OnCreateView method

       LinearLayout layout = FindViewById<LinearLayout>(Resource.Id.ShareLinearLayout);  
        layout.Click += ShareOptionsLayoutOnClick;  
    

    Update

    There is one more solution , you can assign the event directly in xml .

    <LinearLayout  
        android:id="@+id/ShareLinearLayout"  
        android:layout_height="match_parent"  
        android:layout_width="0dp"  
        android:layout_weight="1.5"  
        android:gravity="center"  
        android:clickable="true"  
        android:focusable="true"  
        android:foreground="?attr/selectableItemBackground"  
        android:orientation="horizontal"  
    
    
        android:onClick="ShareOptionsLayoutOnClick"  //add this line  
    
    >  
    

    Modify the ShareOptionsLayoutOnClick method as below

    92073-2.png

    At last ,reference Mono.Android.Export in android project to enable the Export attribute.

    92086-capture.png

    Best Regards,
    Cole Xia


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.