Robin
Robin

Reputation: 128

Dynamic UI for Form

I have this pretty requirement. I am coming trying to come up with an application. My app shall only one Activity. And this activity will have to populate questions for the user based on his previous answer.

I guess for this i have to replace views in order to achieve as above. But what i can't figure out is will this help me to achieve back button click.

for example.

Q1.

---Opt A

---Opt B

if option A is choosen Q2

if option B was choosen Q3

What would be the best approach in designing the UI?

Upvotes: 0

Views: 544

Answers (2)

Paresh Mayani
Paresh Mayani

Reputation: 128428

There are many ways/tricks to implement this layout, among that i would suggest you to implement is ViewFlipper to flip view based on the option selected by user.

After implementing ViewPager you have to write something like:

If user select:

if Option A => then write setDisplayedChild(0);
if Option B => then write setDisplayedChild(1);

Your comment: Let me put abit here. Well I will have around say 100 questions and each questions has an options (2 or more upto 5). So on choosing an option will take me to options questions. You can consider a parent node (has a question) and its path to the child node has an option, and each child node will be another question, so this is what i have to implement. ViewFlipper will not be appicable if i am correct?

=> For this kind of situation do one thing put one question textview and 5 options(radio button) and based on the requirement show/hide the radiobutton and change the title bar textview text.

You can show/hide radiobutton by using setVisibility() method.

For example:

radioButton.setVisibility(View.VISIBLE);  // To make radio button visible
radioButton.setVisibility(View.GONE);  // To hide radio button

Upvotes: 1

Yashwanth Kumar
Yashwanth Kumar

Reputation: 29121

I suggest you to use fragments.

http://developer.android.com/guide/topics/fundamentals/fragments.html

It exactly fills your purpose.

  1. Each fragment can be replaced by another, all fragments replacing actions can be done in single activity.

  2. they have back stack , so when you press back ,you go to previous fragment which will be previous question in your case. you just need to add the replaced fragment in the back stack.

HTH.

Upvotes: 2

Related Questions