I'm not really experienced in app programming so the solution may be simple...
I'm making an app to show scores for a cards game and I wanted to store certain values in another class, namely Round
public class Round {
int[] score1, score2, roem1, roem2;
public void initialize(){
score1 = new int[4];
score2 = new int[4];
roem1 = new int[4];
roem2 = new int[4];
for(int i = 0; i < 4; i++){
score1[i] = 0;
score2[i] = 0;
roem1[i] = 0;
roem2[i] = 0;
}
}
public void setPoints(int game, int s1, int s2) {
score1[game] = s1;
score2[game] = s2;
}
public void setRoem(int game, int r1, int r2) {
roem1[game] = r1;
roem2[game] = r2;
}
public int getPoints1(int game){
return score1[game];
}
public int getPoints2(int game){
return score2[game];
}
public int getRoem1(int game){
return roem1[game];
}
public int getRoem2(int game){
return roem2[game];
}
}
What happens, however, when I try to create the Round object, my app crashes.
It's about the part of the code from the main class.
public class MainActivity extends AppCompatActivity {
Round[] round;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
#Override
public void run() {
round = new Round[4];
for(int i = 0; i < 4; i++){
round[i].initialize();
}
}
}).start();
}
}
What I think is that using another class in an activity crashes the app, but I don't know how to solve it.
Here is the full main activity class
public class MainActivity extends AppCompatActivity {
TextView roundNr, gameNr;
Button roundPlus, roundMinus;
Button gamePlus, gameMinus;
EditText points1, points2;
Round[] round;
String team1, team2;
int roundNumber = 1, gameNumber = 1;
int score1Total, score2Total, roem1Total, roem2Total;
int p;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
#Override
public void run() {
round = new Round[4];
for(int i = 0; i < 4; i++){
round[i].initialize();
}
}
}).start();
roundNr = (TextView) findViewById(R.id.roundNr);
roundNr.setText("1");
gameNr = (TextView) findViewById(R.id.gameNr);
gameNr.setText("1");
roundPlus = (Button) findViewById(R.id.roundPlus);
roundPlus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
roundNumber++;
if (roundNumber <= 4) {
roundNr.setText(Integer.toString(roundNumber));
}
else {
roundNumber--;
}
}
});
roundMinus = (Button) findViewById(R.id.roundMinus);
roundMinus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
roundNumber--;
if (roundNumber >= 1) {
roundNr.setText(Integer.toString(roundNumber));
}
else {
roundNumber++;
}
}
});
gamePlus = (Button) findViewById(R.id.gamePlus);
gamePlus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
gameNumber++;
if (gameNumber <= 4) {
gameNr.setText(Integer.toString(gameNumber));
}
else {
roundNumber++;
if (roundNumber <= 4) {
roundNr.setText(Integer.toString(roundNumber));
gameNumber = 1;
gameNr.setText(Integer.toString(gameNumber));
}
else {
roundNumber--;
gameNumber--;
}
}
}
});
gameMinus = (Button) findViewById(R.id.gameMinus);
gameMinus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
gameNumber--;
if (gameNumber >= 1) {
gameNr.setText(Integer.toString(gameNumber));
}
else {
roundNumber--;
if (roundNumber >= 1) {
roundNr.setText(Integer.toString(roundNumber));
gameNumber = 4;
gameNr.setText(Integer.toString(gameNumber));
}
else {
roundNumber++;
gameNumber++;
}
}
}
});
points1 = (EditText) findViewById(R.id.points1);
points1.setText("0");
points1.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!s.toString().equals("")){
p = Integer.parseInt(s.toString());
points2.setText(Integer.toString(162 - p));
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
points2 = (EditText) findViewById(R.id.points2);
points2.setText("0");
}
}
The problem is that you initialize round variable array, but not round items.
Here's the correct function:
public class MainActivity extends AppCompatActivity {
Round[] round;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
#Override
public void run() {
round = new Round[4];
for(int i = 0; i < 4; i++){
round[i] = new Round();
round[i].initialize();
}
}
}).start();
}
}
I also suggest to modify initialize function and make it a constructor.
Related
I am developing a quiz app. So, in this app user first of all tap on play button and he has to choose category and then he has to choose no of questions and quiz will start.
In quiz activity, problem is that data is not retrieving from firebase firestore in the arraylist. If i did some problem please give the solution.
Below is my code of Main Activity.java where user tap on play button.
package com.example.capitalcamp;
public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,chooseCategory_Activity.class);
startActivity(intent);
}
});
binding.exit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
}
Now user has to choose category. Below is the code of chooseCategoryActivity.java.
package com.example.capitalcamp;
public class chooseCategory_Activity extends AppCompatActivity {
ArrayList<chooseCategoryModal> chooseCategoryArrayList;
chooseCategoryAdapter chooseCategoryAdapter;
ProgressDialog progressDialog;
FirebaseFirestore db;
CollectionReference ref;
ActivityChooseCategory2Binding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityChooseCategory2Binding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
chooseCategoryArrayList = new ArrayList<>();
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading Categories");
progressDialog.setCancelable(false);
progressDialog.show();
StaggeredGridLayoutManager gridLayoutManager = new StaggeredGridLayoutManager(2,
StaggeredGridLayoutManager.VERTICAL);
binding.categoriesRv.setLayoutManager(gridLayoutManager);
binding.categoriesRv.setHasFixedSize(true);
chooseCategoryAdapter = new chooseCategoryAdapter(chooseCategoryArrayList, chooseCategory_Activity.this);
db = FirebaseFirestore.getInstance();
ref = db.collection("Category");
ref.addSnapshotListener(new EventListener<QuerySnapshot>() {
#Override
public void onEvent(QuerySnapshot value, FirebaseFirestoreException error) {
if (error != null) {
Log.d("ErrorCollection", error.getMessage());
return;
}
chooseCategoryArrayList.clear();
for (DocumentSnapshot snapshot: value.getDocuments()){
chooseCategoryModal modal = snapshot.toObject(chooseCategoryModal.class);
modal.setCategoryId(snapshot.getId());
chooseCategoryArrayList.add(modal);
}
chooseCategoryAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
});
binding.categoriesRv.setAdapter(chooseCategoryAdapter);
}
}
Below is the code of chooseCategoryModal.java.
package com.example.capitalcamp;
public class chooseCategoryModal {
String categoryName, categoryId;
public chooseCategoryModal() {
}
public chooseCategoryModal(String categoryName, String categoryId) {
this.categoryName = categoryName;
this.categoryId = categoryId;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
}
Below is the code of chooseCategoryAdapter.java.
package com.example.capitalcamp;
public class chooseCategoryAdapter extends RecyclerView.Adapter<chooseCategoryAdapter.ViewHolder>{
ArrayList<chooseCategoryModal> chooseCategorArrayList;
Context context;
BottomSheetDialog bottomSheetDialog;
static int noOfQuestions = 0;
Boolean cardColorCyan = false;
String categoryName, categoryId;
public chooseCategoryAdapter(ArrayList<chooseCategoryModal> chooseCategorArrayList, Context context) {
this.chooseCategorArrayList = chooseCategorArrayList;
this.context = context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.choose_category_item,parent,false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(chooseCategoryAdapter.ViewHolder holder, int position) {
holder.categ_card.setCardBackgroundColor(getRandomColor());
categoryName = chooseCategorArrayList.get(position).getCategoryName();
categoryId = chooseCategorArrayList.get(position).getCategoryId();
holder.categoryName.setText(categoryName);
holder.categ_card.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
bottomSheetDialog = new BottomSheetDialog(context, R.style.BottomSheetTheme);
View bsView = LayoutInflater.from(context).
inflate(R.layout.choose_ques_bottomsheet_layout,
view.findViewById(R.id.choose_ques_bottomsheet));
bottomSheetDialog.setCancelable(false);
CardView card5 = bsView.findViewById(R.id.five_ques);
CardView card10 = bsView.findViewById(R.id.ten_ques);
CardView card15 = bsView.findViewById(R.id.fifteen_ques);
CardView card20 = bsView.findViewById(R.id.twenty_ques);
CardView card25 = bsView.findViewById(R.id.twentyfive_ques);
CardView card30 = bsView.findViewById(R.id.thirty_ques);
bsView.findViewById(R.id.five_ques).setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
if (cardColorCyan) {
card5.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = false;
noOfQuestions = 0;
} else {
card5.setCardBackgroundColor(Color.CYAN);
card10.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card15.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card20.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card25.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card30.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = true;
noOfQuestions = 5;
}
}
});
bsView.findViewById(R.id.ten_ques).setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
if (cardColorCyan) {
card10.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = false;
noOfQuestions = 0;
} else {
card10.setCardBackgroundColor(Color.CYAN);
card5.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card15.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card20.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card25.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card30.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = true;
noOfQuestions = 10;
}
}
});
bsView.findViewById(R.id.fifteen_ques).setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
if (cardColorCyan) {
card15.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = false;
noOfQuestions = 0;
} else {
card15.setCardBackgroundColor(Color.CYAN);
card5.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card10.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card20.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card25.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card30.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = true;
noOfQuestions = 15;
}
}
});
bsView.findViewById(R.id.twenty_ques).setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
if (cardColorCyan) {
card20.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = false;
noOfQuestions = 0;
} else {
card20.setCardBackgroundColor(Color.CYAN);
card5.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card10.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card15.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card25.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card30.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = true;
noOfQuestions = 20;
}
}
});
bsView.findViewById(R.id.twentyfive_ques).setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
if (cardColorCyan) {
card25.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = false;
noOfQuestions = 0;
} else {
card25.setCardBackgroundColor(Color.CYAN);
card5.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card10.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card15.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card20.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card30.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = true;
noOfQuestions = 25;
}
}
});
bsView.findViewById(R.id.thirty_ques).setOnClickListener(new View.OnClickListener() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void onClick(View view) {
if (cardColorCyan) {
card30.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = false;
noOfQuestions = 0;
} else {
card30.setCardBackgroundColor(Color.CYAN);
card5.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card10.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card15.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card20.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
card25.setCardBackgroundColor(context.getColorStateList(R.color.light_grey));
cardColorCyan = true;
noOfQuestions = 30;
}
}
});
bsView.findViewById(R.id.play_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (noOfQuestions != 0){
bottomSheetDialog.dismiss();
Intent intent = new Intent(context,Quiz_Activity.class);
intent.putExtra("CC_noOfQuestion",noOfQuestions);
intent.putExtra("CC_quizCategory",categoryName);
intent.putExtra("CC_categoryId",categoryId);
context.startActivity(intent);
} else {
Toast.makeText(context, "Choose No of Questions", Toast.LENGTH_SHORT).show();
}
}
});
bsView.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
noOfQuestions = 0;
bottomSheetDialog.dismiss();
}
});
bottomSheetDialog.setContentView(bsView);
bottomSheetDialog.show();
}
});
}
#Override
public int getItemCount() {
return chooseCategorArrayList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView categoryName;
CardView categ_card;
public ViewHolder(View itemView) {
super(itemView);
categoryName = itemView.findViewById(R.id.categoryName);
categ_card = itemView.findViewById(R.id.categ_card);
}
}
private int getRandomColor(){
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
return color;
}
}
Data is not updating in realtime. This is also happened in chooseCategoryActivity but after implementing the below dependency it solved.
implementation "io.grpc:grpc-okhttp:1.32.2"
Below is the code of quizActivity.java.
package com.example.capitalcamp;
public class Quiz_Activity extends AppCompatActivity {
int noOfQuestions;
String quizCategory, categoryId;
ArrayList<QuestionModal> questionModalArrayList;
Random random;
int currentScore = 0, incorrectScore = 0, questionNo = 1;
Handler handler = new Handler();
FirebaseFirestore firestore;
int index = 0;
QuestionModal question;
ActivityQuizBinding binding;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityQuizBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
random = new Random();
questionModalArrayList = new ArrayList<>();
noOfQuestions = getIntent().getIntExtra("CC_noOfQuestion", 0);
quizCategory = getIntent().getStringExtra("CC_quizCategory");
categoryId = getIntent().getStringExtra("CC_categoryId");
addQuestions();
binding.optionA.setOnClickListener(this::onClick);
binding.optionB.setOnClickListener(this::onClick);
binding.optionC.setOnClickListener(this::onClick);
binding.optionD.setOnClickListener(this::onClick);
}
private void addQuestions() {
firestore = FirebaseFirestore.getInstance();
int rand = random.nextInt(5);
firestore.collection("Category")
.document(categoryId)
.collection("Questions")
.whereGreaterThanOrEqualTo("index", rand)
.orderBy("index")
.limit(noOfQuestions)
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (queryDocumentSnapshots.getDocuments().size() < 5) {
firestore.collection("Category")
.document(categoryId)
.collection("Questions")
.whereLessThanOrEqualTo("index", rand)
.orderBy("index")
.limit(noOfQuestions)
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (DocumentSnapshot snapshot : queryDocumentSnapshots) {
QuestionModal questionModal = snapshot.toObject(QuestionModal.class);
questionModalArrayList.add(questionModal);
Toast.makeText(Quiz_Activity.this, "Success 1", Toast.LENGTH_SHORT).show();
}
setNextQuestion();
}
});
Log.d("question success 1","question success 1");
} else {
for (DocumentSnapshot snapshot : queryDocumentSnapshots) {
QuestionModal questionModal = snapshot.toObject(QuestionModal.class);
questionModalArrayList.add(questionModal);
Toast.makeText(Quiz_Activity.this, "Success 1", Toast.LENGTH_SHORT).show();
}
setNextQuestion();
Log.d("question success 2","question success 2");
}
}
});
}
private void showScoreBoard() {
ProgressDialog dialog = new ProgressDialog(Quiz_Activity.this);
dialog.setCancelable(false);
dialog.setMessage("Loading Score Board");
dialog.show();
handler.postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(Quiz_Activity.this, ScoreBoard_Activity.class);
intent.putExtra("quizCategory", quizCategory);
intent.putExtra("noOfQuestions", noOfQuestions);
intent.putExtra("correctAnswers", currentScore);
intent.putExtra("incorrectAnswers", incorrectScore);
startActivity(intent);
finish();
dialog.dismiss();
}
}, 2000);
}
private void setNextQuestion() {
if (index < questionModalArrayList.size()) {
question = questionModalArrayList.get(index);
binding.questionNo.setText("Question " + questionNo++);
binding.progress.setText("Progress: " + (index + 1) + "/" + noOfQuestions);
binding.question.setText(question.getQuestion());
binding.optionA.setText(question.getOptionA());
binding.optionB.setText(question.getOptionB());
binding.optionC.setText(question.getOptionC());
binding.optionD.setText(question.getOptionD());
} else {
showScoreBoard();
}
}
#RequiresApi(api = Build.VERSION_CODES.M)
public void onClick(View view) {
switch (view.getId()) {
case R.id.option_A:
setCardClickable();
checkAnswer(binding.optionA, binding.opACard);
setHandler();
break;
case R.id.option_B:
setCardClickable();
checkAnswer(binding.optionB, binding.opBCard);
setHandler();
break;
case R.id.option_C:
setCardClickable();
checkAnswer(binding.optionC, binding.opCCard);
setHandler();
break;
case R.id.option_D:
setCardClickable();
checkAnswer(binding.optionD, binding.opDCard);
setHandler();
break;
}
}
#RequiresApi(api = Build.VERSION_CODES.M)
private void checkAnswer(TextView option, MaterialCardView card) {
if (option.getText().toString().trim().toLowerCase()
.equals(question.getCorrectAnswer().trim().toLowerCase())) {
currentScore++;
card.setStrokeColor(getColorStateList(R.color.green));
} else {
incorrectScore++;
card.setStrokeColor(getColorStateList(R.color.red));
if (binding.optionA.getText().toString().trim().toLowerCase()
.equals(question.getCorrectAnswer().trim().toLowerCase())) {
binding.opACard.setStrokeColor(getColorStateList(R.color.green));
} else if (binding.optionB.getText().toString().trim().toLowerCase()
.equals(question.getCorrectAnswer().trim().toLowerCase())) {
binding.opBCard.setStrokeColor(getColorStateList(R.color.green));
} else if (binding.optionC.getText().toString().trim().toLowerCase()
.equals(question.getCorrectAnswer().trim().toLowerCase())) {
binding.opCCard.setStrokeColor(getColorStateList(R.color.green));
} else if (binding.optionD.getText().toString().trim().toLowerCase()
.equals(question.getCorrectAnswer().trim().toLowerCase())) {
binding.opDCard.setStrokeColor(getColorStateList(R.color.green));
}
}
}
#RequiresApi(api = Build.VERSION_CODES.M)
private void resetCardStrokeColors() {
binding.opACard.setStrokeColor(getColorStateList(R.color.main_color));
binding.opBCard.setStrokeColor(getColorStateList(R.color.main_color));
binding.opCCard.setStrokeColor(getColorStateList(R.color.main_color));
binding.opDCard.setStrokeColor(getColorStateList(R.color.main_color));
}
private void setCardClickable() {
binding.opACard.setClickable(false);
binding.opBCard.setClickable(false);
binding.opCCard.setClickable(false);
binding.opDCard.setClickable(false);
}
private void setHandler() {
if (index <= questionModalArrayList.size()) {
handler.postDelayed(new Runnable() {
#RequiresApi(api = Build.VERSION_CODES.M)
#Override
public void run() {
resetCardStrokeColors();
index++;
setNextQuestion();
}
}, 2000);
} else {
showScoreBoard();
}
}
}
Below is the code of QuestionModal.java.
package com.example.capitalcamp;
public class QuestionModal {
String Question, OptionA, OptionB, OptionC, OptionD, CorrectAnswer, QuestionId;
Number index;
public QuestionModal(){
}
public QuestionModal( String question, String optionA, String optionB,
String optionC, String optionD, String correctAnswer, String questionId, Number Index) {
Question = question;
OptionA = optionA;
OptionB = optionB;
OptionC = optionC;
OptionD = optionD;
CorrectAnswer = correctAnswer;
QuestionId = questionId;
index = Index;
}
public String getQuestion() {
return Question;
}
public void setQuestion(String question) {
Question = question;
}
public String getOptionA() {
return OptionA;
}
public void setOptionA(String optionA) {
OptionA = optionA;
}
public String getOptionB() {
return OptionB;
}
public void setOptionB(String optionB) {
OptionB = optionB;
}
public String getOptionC() {
return OptionC;
}
public void setOptionC(String optionC) {
OptionC = optionC;
}
public String getOptionD() {
return OptionD;
}
public void setOptionD(String optionD) {
OptionD = optionD;
}
public String getCorrectAnswer() {
return CorrectAnswer;
}
public void setCorrectAnswer(String correctAnswer) {
CorrectAnswer = correctAnswer;
}
public String getQuestionId() {
return QuestionId;
}
public void setQuestionId(String questionId) {
QuestionId = questionId;
}
public Number getIndex() {
return index;
}
public void setIndex(Number index) {
this.index = index;
}
}
Below is the link of screenshot of firestore database.
Firestore Database Image 1
Firestore Database Image 2
In this quiz activity, problem is that data is not retrieving from firebase firestore in the arraylist. If i did some problem please give the solution.
I want all ClickableSpans to have toasts show their own text. But whatever I write in Toast in onClick in for loop, all ClickableSpans show same Toast output. Briefly, I just want ClickableSpans to show different Toasts in for loop. How can I do it? I want all words have clickable. And when all words are clicked, they do different thing. Thank you for your help.
public class MainActivity extends AppCompatActivity {
private String[] textArray;
private String text = "1981 senesinde kuantum bilgisayar fikrini Paul Beniof, Max Planck’ın " +
"enerjinin sürekli olmadan kesikli değerlerde yer alan m, n, k enerji kuantlarıyla ";
private Chronometer chronometer;
private int hold=0;
private TextView textView;
private int i;
private MediaPlayer player;
private long pauseOffset;
private boolean running;
private boolean start=true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textArray = text.split(" ");
final SpannableString ss = new SpannableString(text);
chronometer = findViewById(R.id.chronometer);
chronometer.setFormat("Time: %s");
chronometer.setBase(SystemClock.elapsedRealtime());
textView = findViewById(R.id.text_view);
textView.setText(text);
textView.setTextColor(Color.BLACK);
final ClickableSpan[] clickableSpans = new ClickableSpan[textArray.length];
for(i = 0; i<textArray.length; i++){
clickableSpans[i] = new ClickableSpan() {
#Override
public void onClick(View widget) {
Toast.makeText(MainActivity.this, "", Toast.LENGTH_LONG).show();
}
#Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(Color.BLACK);
ds.setUnderlineText(false);
}
};
final boolean[] c = {true};
chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
#Override
public void onChronometerTick(Chronometer chronometer) {
if ((SystemClock.elapsedRealtime() - chronometer.getBase()) >= 5000&& c[0]) {
for(int i=0; i<textArray.length;i++){
ss.setSpan(clickableSpans[i], hold, hold + textArray[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
hold+=textArray[i].length();
hold++;
}
start=false;
hold=0;
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
if (running) {
chronometer.stop();
pauseOffset = SystemClock.elapsedRealtime() - chronometer.getBase();
running = false;
}
c[0]=false;
}
}
});
hold=0;
}
i=0;
}
public void play(View v) {
if(start){
if (!running) {
chronometer.setBase(SystemClock.elapsedRealtime() - pauseOffset);
chronometer.start();
running = true;
}
}
}
public void stop(View v) {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
New Activity UI load but does not respond, After running onStop() which trigger submit()
List View with the checkbox is bound by a custom adapter. On touch of the Submit button, an intent is triggered which takes me to HomeActivity and onStop() method is triggered which in return call submit method. All submit method is created under a new thread which interfere with UI.
package com.example.cadur.teacher;
public class Attendace extends AppCompatActivity {
DatabaseReference dref;
ArrayList<String> list=new ArrayList<>();
ArrayList<DeatailAttandance> deatailAttandances;
private MyListAdapter myListAdapter;
private ProgressDialog pb;
String year,branch,subject,emailId,pre,abs,rollno,file_name,dat,dat1,roll_str,rollno_present="",rollno_absent="";
int pre_int,abs_int;
ListView listview;
FirebaseDatabase database;
DatabaseReference myRef;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sp=getSharedPreferences("login",MODE_PRIVATE);
final String s=sp.getString("Password","");
final String s1=sp.getString("username","");
year=sp.getString("Year","");
branch=sp.getString("Branch","");
subject=sp.getString("Subject","");
final String attend="Attandence";
emailId=sp.getString("emailId","");
if (s!=null&&s!="" && s1!=null&&s1!="") {
setContentView(R.layout.activity_attendace);
deatailAttandances=new ArrayList<>();
listview = findViewById(R.id.list);
TextView detail=findViewById(R.id.lay);
detail.setText(year+" "+branch+" "+" "+subject);
pb =new ProgressDialog(Attendace.this);
pb.setTitle("Connecting Database");
pb.setMessage("Please Wait....");
pb.setCancelable(false);
pb.show();
database=FirebaseDatabase.getInstance();
myRef=database.getReference(year+"/"+branch);
myRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds:dataSnapshot.getChildren()) {
try {
abs = ds.child("Attandence").child(subject).child("Absent").getValue().toString();
pre = ds.child("Attandence").child(subject).child("Present").getValue().toString();
rollno = ds.getKey().toString();
deatailAttandances.add(new DeatailAttandance(rollno,pre,abs));
myListAdapter=new MyListAdapter(Attendace.this,deatailAttandances);
listview.setAdapter(myListAdapter);
pb.dismiss();
}catch (NullPointerException e){
pb.dismiss();
Intent intent=new Intent(Attendace.this, Login.class);
startActivity(intent);
finish();
}
}
count();
}
#Override
public void onCancelled(DatabaseError error) {
// Failed to read value
}
});
Button selectAll=findViewById(R.id.selectall);
selectAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
myListAdapter.setCheck();
count();
}
});
Button submit_attan=findViewById(R.id.submit_attan);
submit_attan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent =new Intent(Attendace.this,HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
});
Button count=findViewById(R.id.count);
count.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View parentView = null;
int counter=0;
for (int i = 0; i < listview.getCount(); i++) {
parentView = getViewByPosition(i, listview);
CheckBox checkBox=parentView.findViewById(R.id.ch);
if(checkBox.isChecked()){
counter++;
}
}
Toast.makeText(Attendace.this,""+counter,Toast.LENGTH_SHORT).show();
}
});
}else{
SharedPreferences.Editor e = sp.edit();
e.putString("Password", "");
e.putString("username", "");
e.commit();
Intent i=new Intent(Attendace.this,MainActivity.class);
startActivity(i);
finish();
}
}
#Override
protected void onStop() {
Attendace.this.runOnUiThread(new Runnable() {
#Override
public void run() {
submit();
}
});
finish();
super.onStop();
}
public void submit(){
View parentView = null;
final Calendar calendar = Calendar.getInstance();
dat=new SimpleDateFormat("dd_MMM_hh:mm").format(calendar.getTime());
dat1=new SimpleDateFormat("dd MM yy").format(calendar.getTime());
file_name=year+"_"+branch+"_"+dat;
rollno_present=rollno_present+""+year+" "+branch+" "+subject+"\n "+dat+"\n\nList of present Students\n";
rollno_absent=rollno_absent+"\n List of absent Students\n";
for (int i = 0; i < listview.getCount(); i++) {
parentView = getViewByPosition(i, listview);
roll_str = ((TextView) parentView.findViewById(R.id.text1)).getText().toString();
String pre_str = ((TextView) parentView.findViewById(R.id.text22)).getText().toString();
String abs_str = ((TextView) parentView.findViewById(R.id.text33)).getText().toString();
pre_int=Integer.parseInt(pre_str);
abs_int=Integer.parseInt(abs_str);
CheckBox checkBox=parentView.findViewById(R.id.ch);
if(checkBox.isChecked()){
pre_int++;
myRef.child(roll_str).child("Attandence").child(subject).child("Present").setValue(""+pre_int);
myRef.child(roll_str).child("Attandence").child(subject).child("Date").child(dat1).setValue("P");
rollno_present=rollno_present+"\n"+roll_str+"\n";
}else{
abs_int++;
myRef.child(roll_str).child("Attandence").child(subject).child("Absent").setValue(""+abs_int);
myRef.child(roll_str).child("Attandence").child(subject).child("Date").child(dat1).setValue("A");
rollno_absent=rollno_absent+"\n"+roll_str+"\n";
}
}
// Toast.makeText(Attendace.this,"Attendance Updated Successfully",Toast.LENGTH_SHORT).show();
AsyncTask.execute(new Runnable() {
#Override
public void run() {
generateNoteOnSD(Attendace.this,file_name,rollno_present+""+rollno_absent);
}
});
}
public void count(){
View parentView = null;
int counter=0;
for (int i = 0; i < listview.getCount(); i++) {
parentView = getViewByPosition(i, listview);
CheckBox checkBox=parentView.findViewById(R.id.ch);
if(checkBox.isChecked()){
counter++;
}
}
Toast.makeText(Attendace.this,""+counter,Toast.LENGTH_SHORT).show();
}
private View getViewByPosition(int pos, ListView listview1) {
final int firstListItemPosition = listview1.getFirstVisiblePosition();
final int lastListItemPosition = firstListItemPosition + listview1.getChildCount() - 1;
if (pos < firstListItemPosition || pos > lastListItemPosition) {
return listview1.getAdapter().getView(pos, null, listview1);
} else {
final int childIndex = pos - firstListItemPosition;
return listview1.getChildAt(childIndex);
}
}
public void generateNoteOnSD(Context context, String sFileName, String sBody) {
try
{
File root = new File(Environment.getExternalStorageDirectory(),year+"_"+branch+"_Attendance");
if (!root.exists())
{
root.mkdirs();
}
File gpxfile = new File(root, file_name+".doc");
FileWriter writer = new FileWriter(gpxfile,true);
writer.append(sBody+"\n");
writer.flush();
writer.close();
// Toast.makeText(Attendace.this,"File Generated",Toast.LENGTH_SHORT).show();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
Just use
submit();
instead of using
Attendace.this.runOnUiThread(new Runnable() {
#Override
public void run() {
submit();
}
});
and remove finish()
I'm trying to invoke an activity from the MainActivity via a button with OnClickListener
The first activity is responding and works, the second activity doesn't work and crashes the application
Please help me to find the solution
Thanks!!!
here is the code:
class Layout{
public Layout(){
btnStopWatch = (Button)findViewById(R.id.btnStopWatch);
btnTimer = (Button)findViewById(R.id.btnTimer);
}
Button btnStopWatch, btnTimer;
}
class Event{
public Event(){
l.btnStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), StopWatchActivity.class);
startActivity(i);
}
});
l.btnTimer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), TimerActivity.class);
startActivity(i);
}
});
}
}
Layout l; Event e;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
l = new Layout(); e = new Event();
}}
First Activity that works:
public class StopWatchActivity extends AppCompatActivity {
class Layout{
public Layout(){
tvHours = (TextView)findViewById(R.id.tvHours);
tvMinutes = (TextView)findViewById(R.id.tvMinutes);
tvSeconds = (TextView)findViewById(R.id.tvSeconds);
tvBack = (TextView)findViewById(R.id.tvBack);
btnStartStop = (Button)findViewById(R.id.btnStartStop);
btnReset = (Button)findViewById(R.id.btnReset);
}
TextView tvHours, tvMinutes, tvSeconds, tvBack;
Button btnStartStop, btnReset;
}
class Event{
public Event(){
l.btnStartStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(isStarted){
Stop();
}else {
Start();
}
}
});
l.btnReset.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Reset();
}
});
l.tvBack.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
}
});
}
}
Layout l; Event e;
boolean isStarted = false;
int sec = 0, min = 0, hour = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stop_watch);
l = new Layout(); e = new Event();
}
public void Start(){
l.btnStartStop.setText("Stop");
isStarted = true;
Thread t = new Thread(new Runnable() {
#Override
public void run() {
while (isStarted){
try{
Thread.sleep(1000);
runOnUiThread(new Runnable() {
#Override
public void run() {
if(isStarted){
MoveTime();
}
}
});
}catch (InterruptedException e){
}
}
}
});
t.start();
}
public void MoveTime(){
sec++;
if (sec >= 59){
sec = 0;
min++;
if(min >= 59){
min = 0;
hour++;
}
}
UpdateScreen();
}
public void UpdateScreen(){
l.tvHours.setText(Format(hour));
l.tvMinutes.setText(Format(min));
l.tvSeconds.setText(Format(sec));
}
public void CleanScreen(){
l.tvHours.setText("00");
l.tvMinutes.setText("00");
l.tvSeconds.setText("00");
}
public String Format(int i){
if (i<=9){
return "0" + i;
}else{
return Integer.toString(i);
}
}
public void Stop(){
isStarted = false;
l.btnStartStop.setText("Start");
}
public void Reset(){
if(isStarted)
Stop();
CleanScreen();
sec = 0;
min = 0;
hour = 0;
}}
second activity that doesn't work:
public class TimerActivity extends AppCompatActivity {
class Layout {
public Layout() {
etHour = (EditText) findViewById(R.id.etHour);
etHour.setFilters(new InputFilter[]{new InputFilterMinMax("0", "24")});
etMin = (EditText) findViewById(R.id.etMin);
etMin.setFilters(new InputFilter[]{new InputFilterMinMax("0", "59")});
etSec = (EditText) findViewById(R.id.etSec);
etSec.setFilters(new InputFilter[]{new InputFilterMinMax("0", "59")});
btnStartStop = (Button) findViewById(R.id.btnStartStop);
btnReset = (Button) findViewById(R.id.btnReset);
tvBack1 = (TextView)findViewById(R.id.tvBack);
}
EditText etHour, etMin, etSec;
Button btnStartStop, btnReset;
TextView tvBack1;
}
class Event {
public Event() {
l.btnStartStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isStarted) {
Stop();
} else {
Start();
}
}
});
l.btnReset.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Reset();
}
});
l.tvBack1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
}
});
}
}
Layout l;
Event e;
boolean isStarted = false;
int sec = 0, min = 0, hour = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timer);
l = new Layout();
e = new Event();
}
public void Start() {
l.btnStartStop.setText("Stop");
isStarted = true;
Thread t = new Thread(new Runnable() {
#Override
public void run() {
while (isStarted) {
try {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
#Override
public void run() {
if (isStarted) {
MoveTime();
}
}
});
} catch (InterruptedException e) {
}
}
}
});
t.start();
}
public void MoveTime() {
sec = Integer.valueOf(l.etSec.getText().toString());
min = Integer.valueOf(l.etMin.getText().toString());
hour = Integer.valueOf(l.etHour.getText().toString());
sec--;
if (sec < 0) {
sec = 59;
min--;
if (min < 0) {
min = 59;
hour--;
}
}
UpdateScreen();
if (hour == 0) {
if (min == 0) {
if (sec == 0) {
Stop();
}
}
}
}
public void UpdateScreen(){
l.etHour.setText(Format(hour));
l.etMin.setText(Format(min));
l.etSec.setText(Format(sec));
}
public void CleanScreen(){
l.etHour.setText("00");
l.etMin.setText("00");
l.etSec.setText("00");
}
public String Format(int i){
if (i<=9){
return "0" + i;
}else{
return Integer.toString(i);
}
}
public void Stop(){
isStarted = false;
l.btnStartStop.setText("Start");
}
public void Reset(){
if(isStarted)
Stop();
CleanScreen();
sec = 0;
min = 0;
hour = 0;
}}
So I am in the middle of a Challenge from a book I am reading. The challenge says that I do some questions at the users of the app and they should answer True or False. Also they have the option to cheat but when they gone back to the question answer must not be acceptable.
So I created a Boolean Array where I save the status of the "cheater". True if he cheats and False if he doesn't cheat. But after one full rotation of the Questions the Array is Wiped. Why is this happening? What I am doing wrong?
Here is my main code for the Quiz Activity:
public class QuizActivity extends Activity {
private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private Button mCheatButton;
private TextView mQuestionTextView;
private static final String TAG = "QuizActivity";
private static final String KEY_INDEX = "index";
private static final String CHEATER_BOOLEAN = "cheat";
private TrueFalse[] mQuestionBank = new TrueFalse[] {
new TrueFalse(R.string.question_oceans, true),
new TrueFalse(R.string.question_mideast, false),
new TrueFalse(R.string.question_africa, false),
new TrueFalse(R.string.question_americas, true),
new TrueFalse(R.string.question_asia, true),
};
private boolean[] mCheatBank = new boolean[mQuestionBank.length];
private int mCurrentIndex = 0;
private boolean mIsCheater;
private void updateQuestion() {
int question = mQuestionBank[mCurrentIndex].getQuestion();
mQuestionTextView.setText(question);
}
private void checkAnswer(boolean userPressedTrue) {
boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();
int messageResId = 0;
if(mIsCheater) {
messageResId = R.string.judgment_toast;
} else {
if (userPressedTrue == answerIsTrue) {
messageResId = R.string.correct_toast;
} else {
messageResId = R.string.incorrect_toast;
}
}
Toast.makeText(this, messageResId, Toast.LENGTH_SHORT)
.show();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate(Bundle) called");
setContentView(R.layout.activity_quiz);
mQuestionTextView = (TextView)findViewById(R.id.question_text_view);
mQuestionTextView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
mIsCheater = false;
updateQuestion();
}
});
mTrueButton = (Button)findViewById(R.id.true_button);
mTrueButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
checkAnswer(true);
}
});
mFalseButton = (Button) findViewById(R.id.false_button);
mFalseButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
checkAnswer(false);
}
});
mNextButton = (Button)findViewById(R.id.next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
mIsCheater = mCheatBank[mCurrentIndex];
updateQuestion();
}
});
mCheatButton = (Button)findViewById(R.id.cheat_button);
mCheatButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(QuizActivity.this,CheatActivity.class);
boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();
i.putExtra(CheatActivity.EXTRA_ANSWER_IS_TRUE, answerIsTrue);
startActivityForResult(i,0);
}
});
if (savedInstanceState != null) {
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
mIsCheater = savedInstanceState.getBoolean(CHEATER_BOOLEAN, false);
}
updateQuestion();
} // End of onCreate(Bundle) method
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG,"onActivityResult called");
if (data == null) {
return;
}
mIsCheater = data.getBooleanExtra(CheatActivity.EXTRA_ANSWER_SHOWN, false);
mCheatBank[mCurrentIndex] = mIsCheater;
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
Log.d(TAG, "onSaveInstanceState");
savedInstanceState.putInt(KEY_INDEX, mCurrentIndex);
savedInstanceState.putBoolean(CHEATER_BOOLEAN, mIsCheater);
}
Edit 1: Here is the code from the other classes because someone asked.
CheatActivity Code:
public class CheatActivity extends Activity {
public static final String EXTRA_ANSWER_IS_TRUE = "com.bignerrandch.android.geoquiz.answer_is_true";
public static final String EXTRA_ANSWER_SHOWN = "com.bignerdranch.android.geoquiz.answer_shown";
private boolean mAnswerIsTrue;
private boolean mCheater;
private TextView mAnswerTextView;
private Button mShowAnswer;
private void setAnswerShownResult(boolean isAnswerShown) {
Intent data = new Intent();
data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown);
setResult(RESULT_OK, data);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cheat);
mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false);
mAnswerTextView = (TextView)findViewById(R.id.answerTextView);
mCheater = false;
if (savedInstanceState != null) {
mCheater = savedInstanceState.getBoolean(EXTRA_ANSWER_SHOWN, false);
setAnswerShownResult(mCheater);
if (mAnswerIsTrue) {
mAnswerTextView.setText(R.string.true_button);
}
else {
mAnswerTextView.setText(R.string.false_button);
}
} else {
setAnswerShownResult(false);
}
mShowAnswer = (Button)findViewById(R.id.showAnswerButton);
mShowAnswer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mAnswerIsTrue) {
mAnswerTextView.setText(R.string.true_button);
}
else {
mAnswerTextView.setText(R.string.false_button);
}
setAnswerShownResult(true);
mCheater = true;
}
});
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putBoolean(EXTRA_ANSWER_SHOWN, mCheater);
}
}
TrueFalse Code:
public class TrueFalse{
private int mQuestion;
private boolean mTrueQuestion;
public TrueFalse(int question, boolean trueQuestion) {
mQuestion = question;
mTrueQuestion = trueQuestion;
}
public int getQuestion() {
return mQuestion;
}
public void setQuestion(int question) {
mQuestion = question;
}
public boolean isTrueQuestion() {
return mTrueQuestion;
}
public void setTrueQuestion(boolean trueQuestion) {
mTrueQuestion = trueQuestion;
}
}
It's not entirely clear what you mean by wiped. But I think your problem is that you are using a member variable to set your array values. So you are setting each element of your array to that value. So essentially the entire array will be set to what ever the final state of mIsCheater is.