انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
طراحی های مختلف در linearLayout

طراحی های مختلف در linearLayout

#3
(۱۳۹۵/۰۲/۳۱, ۰۹:۲۵ ق.ظ)aliasghar نوشته:
کد:
  int count = 0 ;
   ArrayList<Integer> answers , Question_key ;
   ArrayList<String> Question_text ;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.test);
       answers = new ArrayList<>();

       Question_text = new ArrayList<>() ;
       Question_key = new ArrayList<>() ;

       Question_text.add("سوال 1");//اضاقه کردن سوال ها
       Question_key.add(1);//اضاف کردن کلید سوال ها
       Question_text.add("سوال 2");
       Question_key.add(4);
       Question_text.add("سوال 3");
       Question_key.add(2);
       Question_text.add("سوال 4");
       Question_key.add(3);
       Question_text.add("سوال 5");
       Question_key.add(3);

       for (int i = 0 ; i<Question_text.size() ; i++){
           answers.add(0);//اضافه کردن پاسخ 0
       }

       final TextView tvQuestion = (TextView)findViewById(R.id.question);
       final RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radiogroup);

       radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(RadioGroup group, int checkedId) {
               int answer = 0 ;
               switch (checkedId){
                   case R.id.radio1 :
                       answer = 1 ; // تنظیم پاسخ
                       break;
                   case R.id.radio2 :
                       answer = 2 ;
                       break;
                   case R.id.radio3 :
                       answer = 3 ;
                       break;
                   case R.id.radio4 :
                       answer = 4 ;
                       break;
               }
               answers.remove(count); // حذف پاسخ قبلی
               answers.add(count,answer); //اضافه کردن پاسخ جدید
           }
       });
       final RadioButton radioButton1 = (RadioButton)findViewById(R.id.radio1);
       final RadioButton radioButton2 = (RadioButton)findViewById(R.id.radio2);
       final RadioButton radioButton3 = (RadioButton)findViewById(R.id.radio3);
       final RadioButton radioButton4 = (RadioButton)findViewById(R.id.radio4);


       final Button btn_next = (Button)findViewById(R.id.next);
       final Button btn_previous = (Button)findViewById(R.id.previous);
       btn_next.setText("بعدی");
       btn_previous.setText("قبلی");
       tvQuestion.setText(Question_text.get(count));
       btn_next.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               if (Question_text.size()-1>count) {
                   count++;
                   tvQuestion.setText(Question_text.get(count));
                   btn_previous.setActivated(true);
                   radioButton1.setChecked(answers.get(count) == 1);//علامت زدن پاسخ قبلی
                   radioButton2.setChecked(answers.get(count) == 2);//
                   radioButton3.setChecked(answers.get(count) == 3);//
                   radioButton4.setChecked(answers.get(count) == 4);//
               }else if(Question_key.size()-1>=count){
                   count++;
                   btn_next.setText("پایان");//تغییر متن دکمه ی بعدی بع پایان
               }else {// نمایش نتیجه و پاسخ نامه
                   radioGroup.setVisibility(View.INVISIBLE);
                   btn_next.setVisibility(View.INVISIBLE);//مخفی کردن دکمه ها
                   btn_previous.setVisibility(View.INVISIBLE);
                   String answer_sheet = "پاسخ صحیح - پاسخ شما" ;
                   for (int i = 0 ; i<answers.size() ; i++){
                       answer_sheet+="\n"+ answers.get(i) + " - " + Question_key.get(i);
                   }
                   tvQuestion.setText(answer_sheet);
               }
           }
       });

       btn_previous.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               if (count>0) {
                   count--;
                   btn_next.setText("بعدی");
                   tvQuestion.setText(Question_text.get(count));
                   radioButton1.setChecked(answers.get(count)==1);
                   radioButton2.setChecked(answers.get(count)==2);
                   radioButton3.setChecked(answers.get(count)==3);
                   radioButton4.setChecked(answers.get(count)==4);
               }else{
                   btn_previous.setActivated(false);
               }
           }
       });

   }

موفق باشید


دوست عزیز من از شما خیلی خیلی متشکرم که کمکم کردید ولی توی چند تا کد به خطا خوردم;این کد
کد:
btn_previous.setActivated(true);
 کد رو هم با ctrl+space تغییر دادم ولی درست نشد،ولی وقتی که اون کد رو کامنت کردم برنامه اجرا شد
کد:
((Object) btn_previous).setActivated(false);
در پایان که نتیجه نمایش داده میشه فقط سه گزینه اول رو نشون میده.
ممنون میشم یه توضیحی در مورد کار کرد این کد بدید و یه خواهش دیگه هم دارم ; این که در پایان که نتیجه نشون داده میشه چه طور میشه هر سوال و گزینه هاش نمایش داده بشه و گزینه ای که کاربر انتخاب کرده درسته بوده یا نه "عکس رو ضمیمه کردم"و دکمه برگشت برای کاربر غیر فعال باشه.
من هنوز وقت نکردم که این کدها رو روی پروژه م اعمال کنم،ولی در اولین فرصت انجام میدم و به اطلاعتون میرسونم.*باز هم از شما متشکرم*


فایل‌های پیوست

عکس(ها)
   
پاسخ
 سپاس شده توسط شماره مجازی امارات ، تلگرام ضد فیلتر 2023


پیام‌های این موضوع
طراحی های مختلف در linearLayout - توسط mahdi.39 - ۱۳۹۵/۰۲/۲۹, ۰۲:۱۴ ب.ظ
RE: طراحی های مختلف در linearLayout - توسط aliasghar - ۱۳۹۵/۰۲/۳۱, ۰۹:۲۵ ق.ظ
RE: طراحی های مختلف در linearLayout - توسط mahdi.39 - ۱۳۹۵/۰۳/۰۲, ۱۱:۲۱ ق.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان