字符串中的StartActivity [英] StartActivity from string

查看:107
本文介绍了字符串中的StartActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Xamarin Android Visual Studio中Kalkulator的Aktywnosc字符串启动Activity

I want to start Activity using Aktywnosc string from Kalkulator in Xamarin Android Visual Studio

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文件夹中. 我正在努力: 意图和从字符串开始活动

The Activity is in Resource.biblioteka folder. I'm trying: Intent and start activity from string

还有这个

如何启动新的android使用字符串进行活动?

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

推荐答案

假设这是您要开始的活动:

Assuming this is the Activity that you are trying to start:

namespace SushiHangover
{
    [Activity(Name = "Resources.biblioteka.SomeActivity", Label = "SomeActivity")]
    public class SomeActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
        }
    }
}

使用.Net命名空间/类名称:

var intent = new Intent(this, Type.GetType("SushiHangover.SomeActivity"));
StartActivity(intent);

使用Java包/类名称:

var intent = new Intent(this, Java.Lang.Class.ForName("Resources.biblioteka.SomeActivity"));
StartActivity(intent);

这篇关于字符串中的StartActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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