How I can change ListView items when PagerSlidingTabStrip position changed in xamarin

99 Views Asked by At

I want to make PagerSlidingTabStrip and if tab postion changed then I will load data from specific string array. it changing only integer and it doesn't change string!

this code works fine when i change any integer value with textview

        public override Android.Views.View OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Bundle savedInstanceState)
    {
        var root = inflater.Inflate(Resource.Layout.fragment_card, container, false);
        var text = root.FindViewById<TextView> (Resource.Id.textView);

        if (position==0)
        {
            text.Text = "Card: " + position;
            //greeting();
        }

        ViewCompat.SetElevation(root, 50);
        return root;
    }

But I can't change ListView Adapter

        data d = new data();
    private void getGreeting()
    {
        var list = FindViewById<ListView>(Resource.Id.listview);
        list.Adapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, d.greeting);

    }

this is my data class

public class data
{
    public string[] greeting = { "1)Բարև- Barev", "2)  ինչպե՞ս ես  - inchpes es ",
        "3) Իմ անունն է...Ինչ է քո անունը  - Im anunn e...inch e qo anune?",
        "4) Ո՞րտեղից ես- vorteghits es?", "5)  Ո՞րտեղ ես դու ապրում -Vortegh es du aprum?",
        "6) Հաճելի է ծանոթանալ - hajeli e tsanotanal", "7)  Ինձ նույնպես - Indz nuynpes","8 )  Ինչ է սա  - inch e sa? ",
        "9) Ո՞րտեղ ես կարող եմ գտնել հյուրանոց  - vortegh es karogh em gtnel hyuranots ?",
        "10) Ո՞րտեղ կարող եմ գտնել բնակարան - vortegh karogh em gtnel bnakaran" };
}
1

There are 1 best solutions below

4
jzeferino On

Make your Activity implement ViewPager.IOnPageChangeListener then:

tabs = FindViewById<PagerSlidingTabStrip>(Resource.Id.tabs);

tabs.OnPageChangeListener = this;

and then implement:

public void OnPageScrollStateChanged(int state)
{
    Console.WriteLine("Page scroll state changed: " + state);
}

public void OnPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
    Console.WriteLine("Page Scrolled");
}

public void OnPageSelected(int position)
{
    // Here get the new data and reloadData from list
}