我无法为对话框中的EditText做setText()

时间:2018-12-21 07:30:37

标签: android android-studio dialog

代码就在那儿,从“ edtInfoName.setText(userName)”行出现了错误,这是我不知道为什么。 edtInfoName位于myDialog.xml中。请帮助我找出问题所在。

itnInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText edtInfoName, edtInfoID, edtInfoPW;

                dialogView = (View) View.inflate(MyHome.this, R.layout.info_dialog, null);
                AlertDialog.Builder dlg = new AlertDialog.Builder(MyHome.this);
                dlg.setTitle("User Information");
                dlg.setView(dialogView);
                edtInfoName = (EditText) findViewById(R.id.edtInfoName);
                edtInfoID = (EditText) findViewById(R.id.edtInfoID);
                edtInfoPW = (EditText) findViewById(R.id.edtInfoPW);
                edtInfoName.setText(userName);
                edtInfoID.setText(userID);
                edtInfoID.getFreezesText();
                edtInfoPW.getFreezesText();
            }
        });

1 个答案:

答案 0 :(得分:0)

为此替换代码

<ion-content class="card-background-page">

  <ion-card div class="card">
    <img src="assets/img/rundmc-live.png"/>
    <div class="card-title">São Paulo</div>
    <div class="card-subtitle">41 Listings</div>
  </ion-card>

  <ion-card>
    <img src="img/card-amsterdam.png"/>
    <div class="card-title">Amsterdam</div>
    <div class="card-subtitle">64 Listings</div>
  </ion-card>

</ion-content>


page-home {

    .card-background-page {

        ion-card {
          position: relative;
          text-align: center;
        }

        .card-title {
          position: absolute;
          top: 36%;
          font-size: 2.0em;
          width: 100%;
          font-weight: bold;
          color: #fff;
        }

        .card-subtitle {
          font-size: 1.0em;
          position: absolute;
          top: 52%;
          width: 100%;
          color: #fff;
        }

      }
    }

您正在尝试访问info_dialog.xml中的edittext,因此您需要通过dialogview实例进行访问