0

我正在关注如何使用 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);
        };
    }
}

谢谢和问候,克莱泽

4

3 回答 3

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);  
};
于 2013-08-07T15:08:18.867 回答
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>
于 2012-10-22T06:58:38.033 回答
0

在setonclicklistener之前写下下面的代码,它会解决你的问题。

registerScreen.setText(Html.fromHtml("<font color='#007FFF'><u>Click to Open Next Activity</u></font>"));
registerScreen.setMovementMethod(LinkMovementMethod.getInstance());
于 2012-10-22T07:11:22.820 回答