Forum Xamarin Xamarin.Android

How to call activity based on click of GridView item

Hi All,

I am trying to call android activity on click of GridView item, I have 4 menu option in GridView so want to call activity based on clicked item.
gridView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) {
// here I want to call next activity
};

Kindly suggest that how can I get item value and compare that to call activity.

Thanks
Arun

Answers

  • BerayBentesenBerayBentesen TRUniversity ✭✭✭✭

    StartActivity (typeof(YourActivity));

  • G.ArunG.Arun USMember

    Thanks Beray for answer
    Let me clarify what I want to do, I have created dashboard using GridView and having 4 menu options in that. Each menu has one Activity class and I am not able to call specific activity based on item clicked in GridView. GridView layout is having Image and Text View to show up menu.
    gridView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) {
    Toast.MakeText(this, args.Position.ToString(), ToastLength.Short).Show(); // in this I am only getting item poistion
    StartActivity(typeof(CreateServiceRequest)); // here I am able to call single activity but no decision making call
    };

    So will I get only item position on GridView click and that only be the logic to next Activity?

    If I am not that much clear please let me know any option to connect back to you so I can make you understand complete scenario.

    Thanks,
    G Arun

  • this is my problem toooooo :( please answer this question

  • MabroukMabrouk USMember ✭✭✭
    edited September 2016

    @G.Arun , @AljohnPopeAndrade

    Hi friends,

    1. You need to have an entity class where you save informations about your activitys (Title, Type, ...), like :
      public class Page { public string Title {get; set;} public Type PageType {get; set;} }
    2. In your menu activity where you fill your GridView, you add private List<Page> _pages; and you fill it like :
      _pages= new List<Page>(); _pages.Add(new Page() { Title="Page 1", PageType = typeof(Your_1_activity) } _pages.Add(new Page() { Title="Page 2", PageType = typeof(Your_2_activity) } _pages.Add(new Page() { Title="Page 3", PageType = typeof(Your_3_activity) } _pages.Add(new Page() { Title="Page 4", PageType = typeof(Your_4_activity) }
    3. finally, in your grid view click event it will be easy to show activity , like :
      gridView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) { StartActivity(_pages[args.Position].PageType); // here you are able to call the activity you need };

    Hope that helps :)

    Mabrouk.

  • Sir, very well said thank you so much for this..
    Im a newbee sir btw :) i hope i can ask some question to you when i need help for this gridview haha

  • what is page,title type,pagetype ?

  • MabroukMabrouk USMember ✭✭✭

    @AljohnPopeAndrade
    You are wlcm ;)

Sign In or Register to comment.