我有一个布局(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/