【问题标题】:Set Text not working in dialogue box android在对话框android中设置文本不起作用
【发布时间】:2018-11-11 12:35:36
【问题描述】:

我目前正在做一个项目,当用户单击电子邮件按钮时,它会将他带到一个对话框,他的电子邮件已经插入到编辑文本中,但我面临的问题是 setText 功能没有被实施。 这是我的代码:

Button Emailbtn = (Button) dialog.findViewById(R.id.btnEmail);
Emailbtn.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    v.setSelected(true);
    final Dialog dialog = new Dialog(ViewQuotesD.this);
    dialog.getWindow();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialemail);

    //Getting content for email
    final Button btnsend = (Button) dialog.findViewById(R.id.btnEmail);
    btnsend.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        final EditText emaill = (EditText) dialog.findViewById(R.id.edtEmail);
        emaill.setText(SlectedName);

        String email = emaill.getText().toString().trim();
        String subject = "Your Quotations";
        String message = "Hi " + SelectedEmail +" "+SelectedSurname+"\n"+
                         "FABRIC: \n"+
                         "Total price of fabric = R" + SelectedFabricTotal+
                         "\n"+
                         "LINING: \n"+
                          "Total price of lining = R" + SelectedLiningtotal+
                          "\n"+
                          "LABOUR: \n"+
                          "Total labour cost on fabric = R" + SelectedFabricLabour+
                          "\n"+
                          "VOIL: \n"+
                          "Total price of voil = R" + SelectedVoilTotal +"\n"+
                          "Labour price on voil = R" + SelectedVoilLabour+
                           "\n"+
                           "RAILINGS: \n"+
                           "Total price of railings = R" + SelectedRailTotal+
                           "\n"+
                           "VALANCE: \n"+
                           "Total price of valance = R" + SelectedValTotal+
                           "\n"+
                           "INSTALLATION: \n"+
                           "Total installation cost = R" + SelectedInstall+
                           "\n"+
                           "GRAND TOTAL = R" + SelectedPrice;

        //Creating SendMail object
        SendMail sm = new SendMail(ViewQuotesD.this, email, subject, message);

        //Executing sendmail to send email
        sm.execute();
        finish();
        startActivity(getIntent());
        Toast.makeText(ViewQuotesD.this , "Email sent" , Toast.LENGTH_LONG).show();
      }
    });
  }
});
dialog.show();

我已经测试了变量是否正在被解析,它只是没有在SetText 上实现,即使我尝试使用普通字符串,例如Emaill.setText("test");,它仍然没有显示。

【问题讨论】:

  • 您可以尝试使用emaill.invalidate() 刷新视图。我怀疑它是否能解决问题,但它可能仍然值得一试。
  • @Markaos nope 不幸没有工作
  • 请重建项目或在文件菜单中选择无效缓存并重新启动

标签: android android-edittext settext


【解决方案1】:

如果代码逻辑正确,请检查布局xml文件,可能EditText的内容已经改变,但由于文本颜色与背景颜色相同而无法显示。

尝试更改Edittext颜色进行测试。

【讨论】:

    猜你喜欢
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多