Reputation: 3413
Im new to app development.
I want to add a button on the screen that when clicked will give the user a TextEdit in which he can enter some data. Can anyone give a brief description to how this is done?
Upvotes: 0
Views: 64
Reputation: 44571
I'm not going to write all the code from scratch but I can give you a few pointers that should help. You can create a new EditText
with something like
public void onClick(View v)
{
EditText et = new EditText(v.getContext());
// add layout params, text, etc...
}
Then you need to add it to a ViewGroup
such as a LinearLayout
that is in the currently inflated Layout
with viewGroupName.addView(et)
;
However, a simpler way, if this works for you, is to have the EditText
already defined in your xml and set the visibility
to either invisible
or gone
then set the visibility
in your onClick()
to visible
.
Hopefully this is enough to get you started. If you have any questions feel free to ask.
Upvotes: 1