0

I am using a ListView in Xamarin Android to display a list of restaurants, and when one is clicked on I would like to navigate to a new activity. The activity for each is named using this convention: [restaurantName]Activity. I'm trying to use intents:

    protected override void OnListItemClick(ListView l, View v, int position, long id)
    {
        string t = items[position] + "Activity";
        var intentPlace = new Intent(this, typeof(???));
        StartActivity(intentPlace);
    }

String t gives the correct format, but is the wrong type to put inside the typeof(). However, I have no idea what to put in place of the '???', as I wasn't able to use setTitle in order to create the activity name. Would anyone be able to point me in the right direction?

skchandra
  • 3
  • 5

1 Answers1

1

You need attach full path for your Activities.

var actType = Type.GetType("part of full path" + items[position] + "Activity")

I haven't tested it, but it should work :)

protected override void OnListItemClick(ListView l, View v, int position, long id)
{
    var actType = Type.GetType("part of full path" + items[position] + "Activity")
    var intentPlace = new Intent(this, actType);
    StartActivity(intentPlace);
}

Also usefull if the assembly with activity has been loaded in the current domain

Community
  • 1
  • 1
ivamax9
  • 2,601
  • 24
  • 33
  • I just tried it out, and though it compiled when I clicked on the item I got the error: '[MonoDroid] System.ArgumentException: type [MonoDroid] Parameter name: Type is not derived from a java type.' Is this a feature that is only available in Java? – skchandra Jul 08 '15 at 23:29
  • Okay, what about get fullpath for type via reflection from existing Activity and then put it in "part of full path"? – ivamax9 Jul 08 '15 at 23:33
  • 1
    It worked, I just had to change the path name (I had an extra 'Activity' in there). Thank you! – skchandra Jul 08 '15 at 23:48