将字符串转换为 activity 名称 C#
Convert string to activity name C#
我在 Xamarin Android 中使用 ListView 来显示餐厅列表,当单击其中一个时,我想导航到一个新的 activity。每个的 activity 使用此约定命名:[restaurantName]Activity。
我正在尝试使用意图:
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 来创建 activity 名称。
谁能指出我正确的方向?
您需要附上您的活动的完整路径。
var actType = Type.GetType("part of full path" + items[position] + "Activity")
我还没有测试过,但应该可以:)
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);
}
也有用if the assembly with activity has been loaded in the current domain
我在 Xamarin Android 中使用 ListView 来显示餐厅列表,当单击其中一个时,我想导航到一个新的 activity。每个的 activity 使用此约定命名:[restaurantName]Activity。 我正在尝试使用意图:
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 来创建 activity 名称。 谁能指出我正确的方向?
您需要附上您的活动的完整路径。
var actType = Type.GetType("part of full path" + items[position] + "Activity")
我还没有测试过,但应该可以:)
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);
}
也有用if the assembly with activity has been loaded in the current domain