测验基础应用程序如何识别正确答案

时间:2019-04-30 10:40:36

标签: java android android-recyclerview

我要创建此布局,为此的最佳解决方案是什么 我通过为选项创建5个数组4个数组并为问题创建1个数组并单击来完成此操作,现在我想在选项末尾显示箭头,问题是我现在不知道如何在我的选项中识别正确的选项情况下,如我之前所说,我使用5个数组创建布局,但我认为这样做是不正确的方式
我以某种方式设法在单击的图像上显示勾号,现在我很困惑如何确定正确的答案 我正在展示我的类适配器和主要的Java类。 数据显示在recyclerview及其硬代码数据中。

这是我完整的适配器类

 package com.example.smtrader.adiedtrade.Adapter;
 import android.content.Context;
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
 import android.text.SpannableStringBuilder;
 import android.text.style.ImageSpan;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.RadioGroup;
 import android.widget.TextView;

 import com.example.smtrader.adiedtrade.Acitivities.NewQuizActivity;
 import com.example.smtrader.adiedtrade.Interface.ItemClickListener;
 import com.example.smtrader.adiedtrade.R;

public class NewQuizRecyclerAdapter extends 
RecyclerView.Adapter<NewQuizRecyclerAdapter.ImageVIewHolder> {
private String[] question;
private String[] questionNumber;
private String[] option1;
private String[] option2;
private String[] option3;
private String[] option4;
private Context context;
private String[][] count;

private boolean chooseOption = false;
private boolean selectedOption1 = false;
private boolean selectedOption2 = false;
private boolean selectedOption3 = false;
private boolean selectedOption4 = false;
private int[] answers = new int[getItemCount()];

public NewQuizRecyclerAdapter(String[] question, String[] option1, 
String[] option2,
                              String[] option3, String[] option4) {
    this.question = question;
    this.questionNumber = questionNumber;
    this.option1 = option1;
    this.option2 = option2;
    this.option3 = option3;
    this.option4 = option4;
}

@NonNull
@Override
public ImageVIewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = 
 LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_quiz,
            viewGroup, false);
    context = viewGroup.getContext();
    NewQuizRecyclerAdapter.ImageVIewHolder imageViewHolder = new 
 NewQuizRecyclerAdapter.ImageVIewHolder(view);
    return imageViewHolder;
}

@Override
public void onBindViewHolder(final ImageVIewHolder imageVIewHolder, final 
int i) {
  //  imageVIewHolder.questionnumber.setText(question[i]);
      imageVIewHolder.question.setText(question[i]);
      imageVIewHolder.optiontxt1.setText(option1[i]);
      imageVIewHolder.optiontxt2.setText(option2[i]);
      imageVIewHolder.optiontxt3.setText(option3[i]);
      imageVIewHolder.optiontxt4.setText(option4[i]);

    if (answers[i] == 1) {
        SpannableStringBuilder builder = new SpannableStringBuilder();
        builder.append(imageVIewHolder.optiontxt1.getText()).append(" ",
                new ImageSpan(context, R.drawable.check), 0);
        imageVIewHolder.optiontxt1.setText(builder);
        imageVIewHolder.optiontxt4.setText(option4[i]);
        imageVIewHolder.optiontxt3.setText(option3[i]);
        imageVIewHolder.optiontxt2.setText(option2[i]);
        selectedOption1 = true;
        selectedOption2 = false;
        selectedOption3 = false;
        selectedOption4 = false;

    } else {

    //imageVIewHolder.optiontxt1.setCompoundDrawablesWithIntrinsicBounds
     (R.drawable.uncheck, 0, 0, 0);
      }
    if (answers[i] == 2) {
        SpannableStringBuilder builder = new SpannableStringBuilder();
        builder.append(imageVIewHolder.optiontxt2.getText()).append(" ",
                new ImageSpan(context, R.drawable.check), 0);
        imageVIewHolder.optiontxt2.setText(builder);
        imageVIewHolder.optiontxt1.setText(option1[i]);
        imageVIewHolder.optiontxt3.setText(option3[i]);
        imageVIewHolder.optiontxt4.setText(option4[i]);
        selectedOption1 = false;
        selectedOption2 = true;
        selectedOption3 = false;
        selectedOption4 = false;
    } else {

  //imageVIewHolder.optiontxt2.setCompoundDrawablesWithIntrinsicBounds
    (R.drawable.uncheck, 0, 0, 0);
    }
    if (answers[i] == 3) {
        SpannableStringBuilder builder = new SpannableStringBuilder();
        builder.append(imageVIewHolder.optiontxt3.getText()).append(" ",
                new ImageSpan(context, R.drawable.check), 0);
        imageVIewHolder.optiontxt3.setText(builder);
        imageVIewHolder.optiontxt1.setText(option1[i]);
        imageVIewHolder.optiontxt2.setText(option2[i]);
        imageVIewHolder.optiontxt4.setText(option4[i]);
        selectedOption1 = false;
        selectedOption2 = false;
        selectedOption3 = true;
        selectedOption4 = false;

    } else {
  //    imageVIewHolder.optiontxt3.setCompoundDrawablesWithIntrinsicBounds
        (R.drawable.uncheck, 0, 0, 0);
    }
    if (answers[i] == 4) {
        SpannableStringBuilder builder = new SpannableStringBuilder();
        builder.append(imageVIewHolder.optiontxt4.getText()).append(" ",
                new ImageSpan(context, R.drawable.check), 0);
        imageVIewHolder.optiontxt4.setText(builder);
        imageVIewHolder.optiontxt1.setText(option1[i]);
        imageVIewHolder.optiontxt3.setText(option3[i]);
        imageVIewHolder.optiontxt2.setText(option2[i]);
        selectedOption1 = false;
        selectedOption2 = false;
        selectedOption3 = false;
        selectedOption4 = true;
    } else {

 //imageVIewHolder.optiontxt4.setCompoundDrawablesWithIntrinsicBounds
        (R.drawable.uncheck, 0, 0, 0);
    }
    imageVIewHolder.optiontxt1.setOnClickListener(new 
   View.OnClickListener() {
        @Override
        public void onClick(View view) {
            answers[i] = 1;
            notifyItemChanged(i);
        }
    });
    imageVIewHolder.optiontxt2.setOnClickListener(new 
  View.OnClickListener() {
        @Override
        public void onClick(View view) {
            answers[i] = 2;
            notifyItemChanged(i);
        }
    });
    imageVIewHolder.optiontxt3.setOnClickListener(new 
 View.OnClickListener() {
        @Override
        public void onClick(View view) {
            answers[i] = 3;
            notifyItemChanged(i);
        }
    });
    imageVIewHolder.optiontxt4.setOnClickListener(new 
  View.OnClickListener() {
        @Override
        public void onClick(View view) {
            answers[i] = 4;
            notifyItemChanged(i);
        }
    });
    Log.e("selectoptions", "onBindViewHolder: " + selectedOption1 + 
    selectedOption2 + selectedOption3 + selectedOption4);
   }

  @Override
  public int getItemCount() {
      return NewQuizActivity.question.length;
  }

   public class ImageVIewHolder extends RecyclerView.ViewHolder {
    TextView question, questionnumber, optiontxt1, optiontxt2, optiontxt3, 
  optiontxt4;
    RadioGroup radio;
    ItemClickListener itemClickListener;

    public ImageVIewHolder(final View itemView) {
        super(itemView);
        question = itemView.findViewById(R.id.question);
        radio = itemView.findViewById(R.id.radio);
        optiontxt1 = itemView.findViewById(R.id.option1);
        optiontxt2 = itemView.findViewById(R.id.option2);
        optiontxt3 = itemView.findViewById(R.id.option3);
        optiontxt4 = itemView.findViewById(R.id.option4);
       //questionnumber = itemView.findViewById(R.id.questionNumber);
     }
    }
  }



 and this is my main java class from where i am inflating items in 
 recyclerview




  package com.example.smtrader.adiedtrade.Acitivities;

 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;

 import com.example.smtrader.adiedtrade.Adapter.NewQuizRecyclerAdapter;
 import com.example.smtrader.adiedtrade.R;


 public class NewQuizActivity extends AppCompatActivity {

 private RecyclerView quizRecyclerView;
 private NewQuizRecyclerAdapter mQuizRecyclerAdapter;
 //public static String[] questionNumber = {"Question #1", "Question #2", 
"Question #3", "Question #4", "Question #5", "Question #6", "Question #7", 
"Question #8"};
public static String[] question = {"1. An underlying contract is trading 
at a price of 75. If the underlying price changes, which option price will 
change the most? \n" +
        "A) 1-month 75 call\n" +
        "B) 1-month 80 call\n", "2. In the video, Reda states the one and 
only one reason why liquidity wouldn't matter with our setup\n",
        "3. Why use Futures\n",
        "4. Covered Options\n" +
                "Let's say a trader bought 100 shares of XYZ stock at $56 
per share and sold a 58 call against it for $2. At what price would he 
break even on the trade (not including commissions and fees)?\n",
        "5. Current opt value: 1.24\n" +
                "Delta: 72\n" +
                "Underlying price change: +.18\n" +
                "\n" +
                "To the nearest .01, estimate the option's new value if 
the underlying price changes by the given amount.\n",
        "6. What time frame and what usually happens in a Short Term Delta 
Rush?\n",
        "7. Original Premium = 1.40 \n" +
                "Delta = .16 \n" +
                "Gamma = .14 \n" +
                "Theta = -.03 \n" +
                "Vega = .01\n" +
                "Given this info, if the price of underlying stock 
increases by $2 tomorrow, the new premium would be $__?\n",
        "8. You have a short put position with a 74 strike. At which of 
 these prices would you most likely be assigned at expiration? Select all  
that apply.\n"};
private String[] option1 = {"A) Delta",
        "A) Telecom/Materials/Real Estate/Utilities/Energy/Cons_ 
Staples/lndustrials/Cons. Discret_/Health Care/Technology Technology",
        "A) Technology: 20.84%\n Health Care: 14.90%\n Financials: 1371% 
Cons.\n Discret: 1016%\n Telecom: 9.93%",
        "A) 56 - 2=$54",
        "A) 56 - 2 = $54",
        "A) 5 Day:15 min. volume pours in and we get a fast moving options 
 price per contact",
        "A) 1-month 75 call",
        "A) We are always playing closet OTM call/put and we,re always 
 playing 500 of the biggest stocks in the stock market."};
 private String[] option2 = {"B) Covered Call",
        "B) Technology: 20.84%\n" + "   Health Care: 14.90%\n " + "   
 Financials: 1371% Cons.\n " + "   Discret: 1016%\n " + "   Telecom: 
 9.93%",
        "B) Telecom/Materials/Real Estate/Utilities/Energy/Cons_ 
 Staples/lndustrials/Cons. Discret_/Health Care/Technology Technology",
        "B) 10.25 + (.60 * .40)=10.49",
        "B) 1.24 + (-.15*13.68)=49.35",
        "B) 1.24 + (-.15*13.68)=49.35",
        "B) $1.86\n" +
                "if the underlying stock increased by $2,the new premium 
would be $1.86($1.40+.16+.30)." +
                "Delta is .16 for the first doller move, and the new delta 
is .30 for the second dollar move(.16 + .14)." +
                "Theta ins't a factor since no tiem has passed, and vega 
 ins't a factor because there's no change in implied volatility",
        "B) $1.86\n" +
                "if the underlying stock increased by $2,the new premium 
would be $1.86($1.40+.16+.30)." +
                "Delta is .16 for the first doller move, and the new delta 
 is .30 for the second dollar move(.16 + .14)." +
                "Theta ins't a factor since no tiem has passed, and vega 
 ins't a factor because there's no change in implied volatility"};
private String[] option3 = {"C) We are always playing closest OTM call/put 
and we're always playing 500 of the biggest stocks in the stock market.",
        "C) We are always playing closest OTM call/put and we're always 
playing 500 of the biggest stocks in the stock market.",
        "C) You should use it in conjuction with trading a compoment of 
that future. For ex: Boeing is a component of the Dow jones. you can use 
the Dow jones future to help you determine predicted price range for 
Boeing",
        "C) 24.60 + (-44*-5.20)=26.89",
        "C) 24.60 + (-44*-5.20)=26.89",
        "C) 24.60 + (-44*-5.20)=26.89",
        "C) Delta",
        "C) $73,$73.75,$74\n when the price is lower than the strike by 
even $0.01,the put option " +
                "in in the money and will likely be assigned. When the 
price is at or very near the strike," +
                "the option is at the mon ey and has a strong possibility 
of being assigned. when the price is above the strike," +
                "the call option is out of the money and will almost 
certainly expire worthless."};
private String[] option4 = {"D) I-month 75 call",
        "D) Covered call",
        "D) We are always playing closest OTM call/put and we're always 
playing 500 of the biggest stocks in the stock market.",
        "D) 1.24 + (-15*13.68)=49.35",
        "D) 10.25 + (.60*.40)=10.49",
        "D) 10.25 + (.60*.40)=10.49",
        "C) $73,$73.75,$74\n when the price is lower than the strike by 
even $0.01,the put option " +
                "in in the money and will likely be assigned. When the 
price is at or very near the strike," +
                "the option is at the mon ey and has a strong possibility 
of being assigned. when the price is above the strike," +
                "the call option is out of the money and will almost 
certainly expire worthless.",
        "D) 1-month 75 call"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_quiz);
    init();
 }

 private void init() {
    quizRecyclerView = findViewById(R.id.quizRecyclerView);
    quizRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mQuizRecyclerAdapter = new NewQuizRecyclerAdapter( question, option1, 
  option2, option3, option4);
    quizRecyclerView.setAdapter(mQuizRecyclerAdapter);
 }
}

0 个答案:

没有答案