xamarin widget . get the data from textview

negazirnegazir USMember ✭✭

I'm using xamarin forms, but the widget was built in the android project.
I have many instances of the same widget, each contains different accounts of the user . I'm saving widgetId and account as akey, value in CrossSettings.
But right now all the widgets are updating whenever I call OnUpdate(). I need to get the exact account from my TextView , compare it to the widgetId and update only this widget..

It seems that FindViewById is not supported in widgets. How can i get the text of my textView?

var savedAccount = (TextView)FindViewById(R.Id.accountTextView) // NOT SUPPORTED!
 foreach (var widgetId in appWidgetIds)
 if (SavedAccount.Text == CrossSettings.Current.GetValueOrDefault<string>(widgetId.ToString()))
  //here comes the further update 
Tagged:

Best Answer

Answers

  • edited August 2017

    try that
    private ListView savedAccount;

    savedAccount = FindViewById<TextView>(Resource.Id.accountTextView);

  • negazirnegazir USMember ✭✭
    edited August 2017

    @Me_zy said:
    try that
    private ListView savedAccount;

    savedAccount = FindViewById<TextView>(Resource.Id.accountTextView);

    that's the thing - findViewById doesnt exist as a method here(

  • edited August 2017

    How does the part in your xml with the TextView look like?

  • negazirnegazir USMember ✭✭
    edited August 2017

    @Me_zy said:
    How does the part in your xml with the ListView look like?

    I dont use listview, just a textview.

     <TextView
                        android:id="@+id/accountTextView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp" />
    
  • edited August 2017

    are u using Android.Support.V7.App; ?

  • negazirnegazir USMember ✭✭

    @Me_zy said:
    are u using Android.Support.V7.App; ?

    i don't .

    using Android.App;
    using Android.Appwidget;
    using Android.Content;
    using Android.Views;
    using Android.Widget;
    
  • open your NuGet manager and search for Xamarin.Android.Support.v7.AppCompat and install that.

  • negazirnegazir USMember ✭✭

    Need other variants here...

  • negazirnegazir USMember ✭✭
    Accepted Answer

    I did it by saving data in the cross settings

Sign In or Register to comment.