question

ManojJangir-1715 avatar image
0 Votes"
ManojJangir-1715 asked ManojJangir-1715 commented

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

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


dotnet-xamarin
share.txt (15.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

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

Could you tell us what is the exact problem are you facing? The share part or clicking on linear layout part ?

0 Votes 0 ·

I want to share data on click of the linear layout to whatsapp. I have attached a text file above, there xml file code and .cs file code is written.
In .cs file it is creating a view and in that view user is redirecting to another activity layout on click of the share. I want to disable that layout and share the content to whatsapp.
I am sorry if my question was not clear or if I am asking noobish question.

0 Votes 0 ·

1 Answer

ColeXia-MSFT avatar image
1 Vote"
ColeXia-MSFT answered ManojJangir-1715 commented

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.png (3.9 KiB)
capture.png (11.4 KiB)
· 13
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried this method but the problem is, it is not accepting "FindViewById" and asking to generate a private method for FindViewById. Here I am attaching the screenshot.
91607-image.png


0 Votes 0 ·
image.png (64.7 KiB)

Place the code into OnViewCreated method and modify it as below

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

Thanks it worked. Is there any way where I can remove this OnCreateView method and call the function directly on click event. As in OnCreateView it is creating a view and opening a new layout. If I remove that layout, then there will be some blur screen as OnCreateView will open a new fragment anyhow. So I just do not want the fragment to created or to be opened, just call the function.

0 Votes 0 ·
Show more comments