Android – create EditText programatically

By -
Problem: How to create EditText programatically?
Solution:
[sourecode language=”java”] EditText ed = new EditText(this);

// Type of input that you want from user to input i.e. number, text
ed.setInputType(InputType.TYPE_CLASS_TEXT);

// set the width/height of edittext
ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

// text color
ed.setTextColor(Color.MAGENTA);

// text to view initially inside the edit text
ed.setText(“Hello this is the edittext demo”);
[/sourecode]

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

Loading Facebook Comments ...
Loading Disqus Comments ...