2

I have one Button, and on every click of that button I want to create new EditText Dynamically.

Now my question is , I have one style in style.xml for EditText. Now how can I apply that style to this dynamically created EditText?

My Code for EditText is:

    List<EditText> allEdsLabReport ;
    String[] edsLabReport;
    EditText LabReportNm;

    AddMoreLabReport.setOnClickListener(new View.OnClickListener() 
        {
           @Override
           public void onClick(View v) 
           {

           LabReportNm = new EditText(CaseReport.this);

          allEdsLabReport.add(LabReportNm);

          TableLayout tbl2 = (TableLayout)findViewById(R.id.TableLayoutLabReport);
          TableRow tr1 = new TableRow(CaseReport.this);

          tr1.addView(LabReportNm);
          tbl2.addView(tr1);

      }
        });
Krupa Patel
  • 3,309
  • 3
  • 23
  • 28

2 Answers2

5
new EditText(new ContextThemeWrapper(CaseReport.this, R.style.my_style));
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34
0
LabReportNm.setTextAppearance(getApplicationContext(), R.style.style.xml)

editText.setTextAppearance(getApplicationContext(), R.drawable.demo.xml);
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28