首页 > 解决方案 > Android/MySQL:如何根据 MySQL 的值检查单选按钮

问题描述

目前,根据我上面的问题,我遇到了麻烦。我在一个单选组中有两个单选按钮。第一个单选按钮是“已批准”,第二个单选按钮是“拒绝”。例如,如果我单击单选按钮“已批准”,则该选中单选按钮的值将保存到 MySQL。然后,如果我想显示单选按钮的值,单选按钮“已批准”如何显示为已检查?(不想显示为 TextView)。

下面是关于如何从编辑文本到文本视图中获取所有值的代码。

此代码从数据库中检索并显示为 textView。

    etName = findViewById(R.id.etName);
    etBadgeID = findViewById(R.id.etBadgeID);
    etDepartment = findViewById(R.id.etDepartment);
    etFactory = findViewById(R.id.etFactory);
    etPosition = findViewById(R.id.etPosition);
    etReviewer = findViewById(R.id.etReviewer);
    etTitle = findViewById(R.id.etTitle);
    etMonth = findViewById(R.id.etMonth);
    etYear = findViewById(R.id.etYear);
    etSuggestwill = findViewById(R.id.etSuggestwill);
    etPresent = findViewById(R.id.etPresent);
    etDetails = findViewById(R.id.etDetails);
    etBenefit = findViewById(R.id.etBenefit);
    imgAttach = findViewById(R.id.imgAttach);
    rgStatus = findViewById(R.id.rgStatus);
    etComment = findViewById(R.id.etComment);

    Intent intent = getIntent();
    User user = (User) intent.getSerializableExtra("user");

    etName.setText(user.getName());
    etBadgeID.setText(user.getBadgeid());
    etDepartment.setText(user.getDepartment());
    etFactory.setText(user.getFactory());
    etPosition.setText(user.getPosition());
    etReviewer.setText(user.getReviewer());
    etTitle.setText(user.getTitle());
    etMonth.setText(user.getMonth());
    etYear.setText(user.getYear());
    etSuggestwill.setText(user.getSuggestionwill());
    etPresent.setText(user.getPresent());
    etDetails.setText(user.getDetails());
    etBenefit.setText(user.getBenefit());
    imgAttach.setImageBitmap(base64ToBitmap(user.getPhoto()));
    etComment.setText(user.getComment());

这就是我在数据库中存储值单选按钮的方式(在提交按钮处)

int selectedId = rgStatus.getCheckedRadioButtonId();
radioButton = findViewById(selectedId);
final String status = radioButton.getText().toString();
update(status);

更新方法(状态)

private void update(final String status){
    class updateClass extends AsyncTask<String,Void,String> {

        private ProgressDialog loading;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = 
ProgressDialog.show(NeedApproval.this,"Updating.....",null,true,true);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
        }

        @Override
        protected String doInBackground(String... params) {
            //creating request handler object
            RequestHandler requestHandler = new RequestHandler();

            //creating request parameters
            HashMap<String, String> data = new HashMap<>();
            data.put("status",params[0]);
            //returing the response
            return requestHandler.sendPostRequest(URLs.URL_UPDATE, data);
        }
    }
    updateClass ulc = new updateClass();
    ulc.execute(status);
}

标签: javaandroidmysqlxmlandroid-layout

解决方案


推荐阅读