【问题标题】:EditText returns old value instead of Updated valueEditText 返回旧值而不是更新值
【发布时间】:2017-02-25 10:28:06
【问题描述】:

我获得了数据库条目并将它们显示在编辑文本中。我想改变它并更新它。但即使我能够更改,当我尝试从 EditText 获取文本时,它也会返回其旧值而不是更新值。

private void getServicesFromLayout(View view){

       ...........
            if(checkDatabase() == null){
                try{
                    companyNo = Integer.parseInt(mCompanyNumber.getText().toString());
                    seasonNo = Integer.parseInt(mPeriodNumber.getText().toString());
                    servicePath = mServicePath.getText().toString();
                }catch (Exception e){
                    e.printStackTrace();
                }
                addNewService(servicePath,companyNo,seasonNo);
            }else{
                try{
                    **companyNo = Integer.parseInt(mCompanyNumber.getEditableText().toString());
                    seasonNo = Integer.parseInt(mPeriodNumber.getText().toString());
                    servicePath = mServicePath.getText().toString();**
                }catch (Exception e){
                    e.printStackTrace();
                }
                int result = updateDatabase(servicePath ,companyNo ,seasonNo ,getEntryID());
                Toast toast = Toast.makeText(globalContext,String.valueOf(result),Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }


        }


    }

在这里,我正在检查数据库是否为空,我正在添加新服务,如果它不为空,我正在尝试更新现有服务。但我无法从edittext 获得新价值。它返回旧值

mSaveConnectionInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try{
                    displayLatestEntry(getLatestServiceToDisplay());
                    if(isTestOk){
                        **getServicesFromLayout(v);**
                        isTestButtonClicked = 0;

这里叫...

【问题讨论】:

  • 编辑文本中的值是从数据库设置的还是从用户设置的?
  • 从数据库中设置
  • 请编辑您的问题以发布minimal code that reproduces the problem that you're asking about。无论如何,没有难过的感觉,欢迎来到 StackOverflow :)
  • 你在哪里使用这个代码?使用哪种方法(单击、onCreate 或其他方法)?
  • 此代码是从 onCreate 调用的自定义函数的一部分

标签: android android-studio get android-edittext getvalue


【解决方案1】:

当您从编辑文本更新文本时更新您的数据库条目。

【讨论】:

  • 我正在更新它,但我无法从 EditText 获取新值。
猜你喜欢
  • 1970-01-01
  • 2021-02-05
  • 1970-01-01
  • 1970-01-01
  • 2020-05-06
  • 1970-01-01
  • 2021-01-02
  • 2021-06-15
  • 1970-01-01
相关资源
最近更新 更多