EditText inside AlertDialog always null

前端 未结 3 1241
孤城傲影
孤城傲影 2020-12-07 04:07

I\'ve search over the threads but so far I have not found what I\'m looking for. I created a custom Alert Dialog that show up and I can do almost anything with it. It custom

3条回答
  •  臣服心动
    2020-12-07 04:32

    When you use findViewById you implicitly refer to the current activity. The part you have to change is

    EditText txtAccName = (EditText) ad.findViewById(R.id.txtEditName);
    

    instead of

    EditText txtAccName = (EditText) findViewById(R.id.txtEditName);
    

    when you attempt to resolve it. You'll also have to change the scope of the AlertDialog object ad to class-wide and make sure that it's not null, before you search for views in it. That's pretty much it.

提交回复
热议问题