0

I want to insert TextInputEditText within the TextInputLayout programmatically, but, I can not do it, because I don't now how to do this and only my EditText is being displayed. OBS: the method is responsable to add 3 times, an EditText, but now I want to insert an TextInputLayout instead EditText

private void configLayout(View view, LinearLayout ll) {
    String[] hint = new String[]{"Name", "E-mail", “Phone”};
    for (int i = 0; i < 3; i++) {

    LinearLayout temp = new LinearLayout(view.getContext());
    temp.setOrientation(LinearLayout.VERTICAL);
    temp.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextInputEditText et = new TextInputEditText(view.getContext());
    et.setHint(hint[i]);
    LinearLayout.LayoutParams llpNome = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    llpNome.setMargins(0, 16, 0, 0);
    et.setLayoutParams(llpNome);
    temp.addView(et);

    TextInputLayout til = new TextInputLayout(view.getContext(), null, R.style.stl_til);
    LinearLayout.LayoutParams llpTil = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    llpTil.setMargins(0, 16, 0, 0);
    til.setLayoutParams(llpTil);
    til.setHint(hint[i]);
    temp.addView(til);

    ll.addView(temp);
}

}

  • 1
    "because the app crashes" -- use LogCat to examine the Java stack trace associated with your crash. – CommonsWare Apr 21 '18 at 00:45
  • @CommonsWare nothing is displayed. It's very strange. It happens when I add **til.addView(et)** below of **temp.addView(til)** – Wallace Blend Apr 21 '18 at 00:54
  • 1
    If you are crashing, there should be a Java stack trace. Try disabling any filters in the LogCat view. Without a stack trace, it will be difficult for anyone to help you. – CommonsWare Apr 21 '18 at 00:59
  • Nothing is displayed (Run and Logcat). Even so, do you know how I put the effect on TextInputLayout so that when I touch it, the hint goes up, OR, put the TextInputEditText inside the TextInputLayout? – Wallace Blend Apr 21 '18 at 01:31
  • 2
    Remove `temp.addView(et);`. You're trying to add `et` to two parents, which you can't do. You want `et` to be a child of the `TextInputLayout`, not the `LinearLayout`, so just do `til.addView(et);`. – Mike M. Apr 21 '18 at 01:31
  • It works now @MikeM. ! Thank you so much! Anser this post, So I'll give you the best answer check for you – Wallace Blend Apr 21 '18 at 01:35
  • No problem. It's cool. I've already marked this as a duplicate. Thank you, though. Please do look into how to get the stack traces for your crashes. It'll make things a lot easier. The first linked duplicate might be of some help in that regard. Glad you got it working. Cheers! – Mike M. Apr 21 '18 at 01:37
  • Ok, thanks! And thanks @CommonsWare also! – Wallace Blend Apr 21 '18 at 01:42

0 Answers0