将字符串转换为活动名称C# [英] Convert string to activity name C#

查看:131
本文介绍了将字符串转换为活动名称C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin的Andr​​oid一个ListView显示的餐馆列表,当一个人被点击我想导航到一个新的活动。 [restaurantName]活动:每个活动使用此约定命名。 我试图用意向:

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);
    }

串T给出了正确的格式,但它是错误的类型将typeof运算()内。不过,我不知道放什么到位???,因为我没能使用的setTitle,以创建活动名称。 会有人能指出我朝着正确的方向吗?

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?

推荐答案

您需要附上完整路径,你的活动。

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);
}

也有用如果与活动,大会已在当前域中加载

这篇关于将字符串转换为活动名称C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆