Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Fragment;
- import android.content.res.Resources;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.support.v4.app.FragmentTransaction;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.RadioButton;
- import android.widget.TextView;
- import java.util.Random;
- public class TemperFragment extends android.support.v4.app.Fragment {
- private TextView question;
- private RadioButton first, second, third;
- private TextView textdata;
- private int page;
- private TextView textindicator;
- private String answers1[],answers2[],answers3[],answers4[],answers5[],answers6[];
- private String questions[];
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Resources res = getResources();
- questions = res.getStringArray(R.array.test_questions);
- answers1 = res.getStringArray(R.array.answers_one);
- answers2 = res.getStringArray(R.array.answers_two);
- answers3 = res.getStringArray(R.array.answers_three);
- answers4 = res.getStringArray(R.array.answers_four);
- answers5 = res.getStringArray(R.array.answers_five);
- answers6 = res.getStringArray(R.array.answers_six);
- }
- public static TemperFragment newInstance(int page)
- {
- TemperFragment temperFragment = new TemperFragment();
- Bundle args = new Bundle();
- args.putInt("someInt",page);
- temperFragment.setArguments(args);
- return temperFragment;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- ViewGroup rootView = (ViewGroup) inflater.inflate(
- R.layout.test_temper, container, false);
- page = getArguments().getInt("someInt");
- textdata = (TextView) rootView.findViewById(R.id.present_text);
- question = (TextView) rootView.findViewById(R.id.question_text);
- textdata = (TextView) rootView.findViewById(R.id.present_text);
- first = (RadioButton) rootView.findViewById(R.id.first_answer);
- second = (RadioButton) rootView.findViewById(R.id.second_answer);
- third = (RadioButton) rootView.findViewById(R.id.third_answer);
- textindicator = (TextView) rootView.findViewById(R.id.textIndicator);
- TypefaceInit typefaceInit = new TypefaceInit(getContext());
- first.setTypeface(typefaceInit.getRobotoThin());
- second.setTypeface(typefaceInit.getRobotoThin());
- third.setTypeface(typefaceInit.getRobotoThin());
- textdata.setTypeface(typefaceInit.getRobotoMedium());
- switch (page)
- {
- case 1:
- {
- textdata.setText(getText(R.string.firstText).toString());
- textindicator.setText(page+"");
- rootView.setBackgroundColor(Color.parseColor(randColor()));
- }
- case 2:
- {
- question.setText(questions[0].toString());
- first.setText(answers1[0]);
- second.setText(answers1[1]);
- third.setText(answers1[2]);
- textindicator.setText(page+"");
- rootView.setBackgroundColor(Color.parseColor(randColor()));
- }
- case 3:
- {
- question.setText(questions[1].toString());
- first.setText(answers2[0]);
- second.setText(answers2[1]);
- third.setText(answers3[2]);
- textindicator.setText(page+"");
- rootView.setBackgroundColor(Color.parseColor(randColor()));
- }
- case 4:
- {
- question.setText(questions[2]);
- first.setText(answers3[0]);
- second.setText(answers3[1]);
- third.setText(answers3[2]);
- textindicator.setText(page+"");
- rootView.setBackgroundColor(Color.parseColor(randColor()));
- }
- case 5:
- {
- question.setText(questions[3].toString());
- first.setText(answers4[0]);
- second.setText(answers4[1]);
- third.setText(answers4[2]);
- textindicator.setText(page+"");
- rootView.setBackgroundColor(Color.parseColor(randColor()));
- }
- case 6:
- {
- question.setText(questions[4].toString());
- first.setText(answers5[0]);
- second.setText(answers5[1]);
- third.setText(answers5[2]);
- textindicator.setText(page+"");
- rootView.getRootView().setBackgroundColor(Color.parseColor(randColor()));
- }
- case 7:
- {
- question.setText(questions[5].toString());
- first.setText(answers6[0]);
- second.setText(answers6[1]);
- third.setText(answers6[2]);
- textindicator.setText(page+"");
- rootView.setBackgroundColor(Color.parseColor(randColor()));
- }
- case 8:
- {
- }
- }
- return rootView;
- }
- public String randColor()
- {
- String []cont = {"#189fff","#ff440d","#14c239","#9121e8"};
- return cont[ new Random().nextInt(cont.length)];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment