java - Dynamic User Input Forms -
i want collect information user. let's say, want collect information age , gender each of family members.
how this, in form, given not know family size, when prompted, can input number of family members. screen shows, form list family member 1:
age:
gender:
family member 2:
age
gender
, on. 1 big list, scroll down app input information. , submit button @ end submit form me. don't know how handle unknown number of edittext forms etc , how extract info each.
if show me how code snippets.
there many different way mention 1 of them:
-start have layout of edittext , button. size of family question -layout viewpager -layout fragement, how u want form example 2 edittext (age , gender) , 1 button
-create fragment.java class , inflate fragment layout inside it
now on main activity set first layout size of family layout.
for example enters 4.
now open new activity viewpager layout content.
int size = 4; arraylist<fragments> lf = new arraylist<fragment>();
create fragments loop
for(int count;0 count<size; count ++){ fragment f = new fragment(); lf.add(f); }
now create pageradapter passing "lf" it
you can set text every button accordingly
string text; if(pagenumber == size-1) //means last page text= "finish"; else text = "next";
then
button.settext(text);
update clarification
- firstfragment.xml should have want in form (2 edittexts , 1 button)
- main_pager.xml has viewpager
- create mainactivity.java class
setcontentview(r.layout.main_pager);
- in oncreate() find viewpager , give viewpager instance.
- after above loop explained according size of family
now call setadapter on viewpager . ex:
vpager.setadapter(new fragmentadapter(getfragmentmanager(), lf));
here fragmentadapter class.
public class fragmentadapter extends fragmentpageradapter{ private list<fragment> fragments; public fragmentadapter (fragmentmanager fm, list<fragment> fragments) { super(fm); this.fragments = fragments; } @override public fragment getitem(int position) { return this.fragments.get(position); } @override public void destroyitem (viewgroup container, int position, object object) { super.destroyitem(container, position, object); } @override public int getcount() { return this.fragments.size(); } }
Comments
Post a Comment