-1

我正在android中构建一个登录系统,我需要完成以下工作:

  • 将用户数据保存在本地存储中
  • 当创建用户并且我按下按钮时,它需要动态创建一个带有用户名和短名称的单选按钮。

我已经设法完成了这些事情,但我现在唯一的问题是我想要有 2 个类,一个是您注册帐户的地方,另一个是显示带有用户数据的单选按钮的地方。所以我的问题是:我如何对 calss 进行编程,以便当我按下注册按钮时,它会在不同的类中创建单选按钮。

下面是类的代码:

enter code here






@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.Save:

        Intent I = new Intent();
        I.putExtra(
        I.setClass(this, ShowUsers.class);
        startActivity(I);
        break;

    }

}

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    // Start other Activity
    switch (v.getId()) {
    case R.id.create:
        Intent intent = new Intent();
        intent.setClass(Main.this, Register.class);
        startActivity(intent);
        break;

    }

    Bundle extras = getIntent().getExtras(); 
    String userName;

    if (extras != null) {
        userName = extras.getString("editTextName,editTextPassword,editTextshortname");
        // and get whatever type user account id is
    }

}

}

当我单击保存按钮时,它需要在主类中创建单选按钮,现在的问题是我该如何完成?

4

1 回答 1

0

如果第二个类是 Activity,那么一种解决方案是向其发送Intent创建单选按钮所需的数据。为此,您可以创建一个Intent对象,调用其任何setExtra()方法,然后startActivity()使用Intent. 查看 Android API 文档了解更多详细信息。

于 2012-11-08T20:22:29.047 回答