【问题标题】:open radio buttons in different class打开不同类中的单选按钮
【发布时间】:2012-11-08 20:20:15
【问题描述】:

我正在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
    }

}

}

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

【问题讨论】:

  • 问题有点长,大家可能不想看。请去掉所有对问题不重要的代码。

标签: android class login radio-button sharedpreferences


【解决方案1】:

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

【讨论】:

  • 但我不明白应该在 putextra 行中放什么
  • @UgurErtas 你读过 API 文档吗?你不明白哪一部分?
猜你喜欢
  • 1970-01-01
  • 2011-10-08
  • 2017-07-24
  • 1970-01-01
  • 2020-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-03
相关资源
最近更新 更多