c# - 在包含的布局的 TextView 中添加点击监听器

标签 c# android xamarin

我有一个布局(MenuLayout),其中有一个textView(注销)。我想在该 TextView 中添加一个点击监听器。我将此布局包含在另一个布局中。

这是代码

<p.FlyOutContainer xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/FlyOutContainer">
<include
    layout="@layout/menuLayout"/>
<include
    layout="@layout/Home" />

我正在为注销的点击事件编写代码,如下所示

TextView logout = FindViewById<TextView> (Resource.Id.textViewLogout);


        logout.Click += delegate {
            Intent logOut = new Intent(this,typeof(MainActivity));
            StartActivity(logOut);
        };

但是点击事件不起作用。 谁能告诉我我犯错误的解决方案。

这是Link我正在使用的源代码。

最佳答案

Xamarin 中的另一种方式是:

TextView logout = FindViewById<TextView> (Resource.Id.textViewLogout);

logout.Click += logout_Click;


void logout_Click(object sender, EventArgs e)
{
    Intent logOut1 = new Intent(this,typeof(MainActivity));
    StartActivity(logOut1);
}

已编辑:尝试使用其他名称来表达您的 Intent ,以防万一。

关于c# - 在包含的布局的 TextView 中添加点击监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21374511/

相关文章:

xamarin - 如何在xamarin表单中使用X和Y坐标定位按钮?

c# - 使用具体类型覆盖通用方法(类型参数 * 隐藏类 *)

c# - 是否可以在 Web api 路由中使用 .json?

C# API HTTP 动态参数

Android Studio - "aidl is missing"...不,不是

Android 10 - 作为存储在应用主目录中的子进程启动可执行文件的替代方法

c# - 属性(property)已由 'FrameworkElement' 注册

android - 如何获得共享 Intent 的结果?

java - Android 如何允许来自特定服务器的特定 SSL 证书

c# - 带有 MvxSpinner 的 MvxListView 在第一个项目上显示空条目