0

I am making an activity in which an alertDialog will appear. The dialog will have a view which contains: Linear layout with two editText (Numeric texts) and then setHeight(wrapContent). You can see below.

enter image description here

Hope you are understanding now what i am doing. Here the view is a xml file which i created and it is not the activity's xml file. Now I want that when a user put the pin in the editText then i can get it and confirm it or whatever i want. But the problem is that i am not getting anything when i call getText(). Here is my code.


LayoutInflater factory = getLayoutInflater();
        View view = factory.inflate(R.layout.zalert_pass_enable, null); // zalert_pass.. is the xml file

        EditText passInput1 = view.findViewById(R.id.inputPass);
        EditText passInput2 = view.findViewById(R.id.inputPassConfirm);

       String value = passInput1.getText().toString().trim();

I edited my code to so that you can understand, this is not the actual code but it can easily tell my problem. When i toast the value String then i get nothing. Like there are 0 charaters. But i am putting 4 charaters at least each time. Now i know that the problem is in the process of linking the xml file to inflator.

 infalInflater.inflate(R.layout.list_item, parent, false);

See the above line of code. This a well upvoted answer of stackOverflow. which tells us that we should not null the inflator. We should give it parent. But what will be the parent in my case.

enter image description here

You can see the picture and that is my problem and i want a solution for that, please help.

Vijay
  • 1,163
  • 8
  • 22

1 Answers1

1

Add this line Dialog dialog = new Dialog(context); after you are inflating view and use it to get edittext object like this

LayoutInflater factory = getLayoutInflater();
    View view = factory.inflate(R.layout.zalert_pass_enable, null); 
    Dialog dialog = new Dialog(context); // add this line
    EditText passInput1 = dialog.findViewById(R.id.inputPass);
    EditText passInput2 = dialog.findViewById(R.id.inputPassConfirm);

   String value = passInput1.getText().toString().trim();
Quick learner
  • 10,632
  • 4
  • 45
  • 55
  • this is not a problem, my problem is stated at the end of the question – Vijay Sep 01 '20 at 12:07
  • 1
    Actually, your answer gave me a hint. It was not completely correct. Problem was I was putting getActivity() instead of getContext(). Second wrong part was alert.view(R.layout.xmlFile) and the correct one was alert.view(view). This is how it is working. thanks – Vijay Sep 01 '20 at 12:19