tags:

views:

61

answers:

2

Hi. How do i add and remove views such has textviews from an android app like how you can on the original stock android contacts screen where you press a small icon on the right side of a field and it will either add or delete a field which consists of a textview and a editTextView from what i can see.

Any examples on how to achieve this?

Thanks in advance

+3  A: 

Hi You can try this way by adding relative layout and than add textview in that.

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            (LayoutParams.WRAP_CONTENT), (LayoutParams.WRAP_CONTENT));

RelativeLayout relative = new RelativeLayout(getApplicationContext());
relative.setLayoutParams(lp);

TextView tv = new TextView(getApplicationContext());
tv.setLayoutParams(lp);

EditText edittv = new EditText(getApplicationContext());
edittv.setLayoutParams(lp);

relative.addView(tv);
relative.addView(edittv);
krunal shah
Will that autamtically add a new view to the layout without reloading the whole screen? much like how u add a new textfield in contacts?
jonney
Android has to redraw the screen when you add a new view (I think). But it shouldn't affect you in most cases
Falmarri