我正在关注如何使用Mono For Android创建登录和注册流程的示例代码。该示例是在java中开发的,我一直坚持如何在Mono For Android中实现setOnClickListener。
请找到以下代码。
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting default screen to login.xml
setContentView(R.layout.login);
TextView registerScreen = (TextView) findViewById(R.id.link_to_register);
// Listening to register new account link
registerScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(i);
}
});
}
}
有人可以指导我如何做到这一点。
- 修改
public class LoginActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView(Resource.Layout.LoginLayout);
TextView registerScreen = (TextView)FindViewById(Resource.Id.link_to_register);
registerScreen.Click += (sender, e) =>
{
Intent i = new Intent(this, typeof(RegisterActivity));
this.StartActivity(i);
};
}
}
谢谢和问候, klaydze
答案 0 :(得分:0)
您是否在AndroidManifest.xml
?
<activity
android:name=".RegisterActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.REGISTERACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
答案 1 :(得分:0)
在setonclicklistener之前写下代码,它将解决您的问题。
registerScreen.setText(Html.fromHtml("<font color='#007FFF'><u>Click to Open Next Activity</u></font>"));
registerScreen.setMovementMethod(LinkMovementMethod.getInstance());
答案 2 :(得分:0)
尝试使用更短的代码
TextView tV = (TextView)app.FindViewById(Resource.Id.mytextview);
tV.Click += (s, e) =>
{
StartActivity(typeof(RegisterActivity));
//this is what you currently have
//var registerActivity = new Intent (this, typeof(RegisterActivity));
//StartActivity(registerActivity);
};