我想在Xamarin Android Visual Studio中使用Kalkulator中的Aktywnosc字符串启动Activity
public class Kalkulator
{
public int Id { get; set; }
public string Nazwa { get; set; }
public string Aktywnosc { get; set; }
public string Krotki_opis { get; set; }
public string Zrodlo { get; set; }
public string Ineksowanie { get; set; }
}
活动位于Resource.biblioteka文件夹中。 我尝试着: Intent and start activity from string
和这个
How can I start a new android activity using a string?
var e_nacisniety = Kalkulator.Lista_kalkulatorow().First(p=>p.Id == e.Position);
var act = "Resources.biblioteka." + e_nacisniety.Aktywnosc;
StartActivity(new Intent().SetClassName(this, act));
答案 0 :(得分:1)
假设这是您尝试启动的活动:
namespace SushiHangover
{
[Activity(Name = "Resources.biblioteka.SomeActivity", Label = "SomeActivity")]
public class SomeActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
}
}
var intent = new Intent(this, Type.GetType("SushiHangover.SomeActivity"));
StartActivity(intent);
var intent = new Intent(this, Java.Lang.Class.ForName("Resources.biblioteka.SomeActivity"));
StartActivity(intent);