1

我正在尝试登录我的网站,需要弄清楚如何将单选按钮选项转换为字符串,然后将其转换为 EditText。

public class HttpLogin extends Activity {
    private Button login;
    private EditText company, username, password;
    private int radioCheckedId;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        login = (Button) findViewById(R.id.button1);
        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioCompany); 
        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
        {
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                radioCheckedId = checkedId;
                if(radioCheckedId==1){
                    company=R.string.a_e;
                }
                if(radioCheckedId==2){
                    company=R.string.stat_o;
                }
                else{
                    Toast.makeText(getApplicationContext(), "Please choose a company.",
                               Toast.LENGTH_LONG).show();
                }

            }
        });
        username = (EditText) findViewById(R.id.editText1);
        password = (EditText) findViewById(R.id.editText2);

        login.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                String mCompany = company.getText().toString();
                String mUsername = username.getText().toString();
                String mPassword = password.getText().toString();

                tryLogin(mCompany, mUsername, mPassword);
            }
        });
    }
4

1 回答 1

0

获取 Radio Group 的引用,然后使用 radio group 的 getCheckedInId 方法找到选中的单选按钮,然后获取该 id 对应的单选按钮,然后在其上调用 getText 方法。

希望对你有帮助!!

于 2012-10-10T07:35:18.643 回答