Commit 0b016b4f authored by Hasaranga Nadeesh's avatar Hasaranga Nadeesh

grade one test

parent 366a786d
package com.example.myapplicationrp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class GradeOne01 extends AppCompatActivity {
EditText ans1,ans2,ans3,ans4,ans5;
Button save;
DatabaseReference ref;
Child child;
long maxid=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grade_one01);
ans1 = (EditText)findViewById(R.id.answer1);
ans2 = (EditText)findViewById(R.id.answer2);
ans3 = (EditText)findViewById(R.id.answer3);
ans4 = (EditText)findViewById(R.id.answer4);
ans5 = (EditText)findViewById(R.id.answer5);
save = (Button)findViewById(R.id.button);
child = new Child();
ref = FirebaseDatabase.getInstance().getReference().child("Child");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
maxid = (dataSnapshot.getChildrenCount());
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int passCount = 0;
int failCount = 0;
if(ans1.getText().toString().equals("2")){
passCount+= 1;
}
if(ans2.getText().toString().equals("4")){
passCount+=1;
}
if(ans3.getText().toString().equals("7")){
passCount+=1;
}
if(ans4.getText().toString().equals("11")){
passCount+=1;
}
if(ans5.getText().toString().equals("9")){
passCount+=1;
}
failCount = 5 - passCount;
child.setAnswer1(ans1.getText().toString());
child.setAnswer2(ans2.getText().toString());
child.setAnswer3(ans3.getText().toString());
child.setAnswer4(ans4.getText().toString());
child.setAnswer5(ans5.getText().toString());
child.setCorrectAns(String.valueOf(passCount));
child.setIncorrectAns(String.valueOf(failCount));
ref.child(String.valueOf(maxid+1)).setValue(child);
Toast.makeText(GradeOne01.this,"Data Inserted",Toast.LENGTH_SHORT).show();
if(!(ans1.getText().toString().equals("2"))){
openDialog();
}
}
});
}
public void openDialog(){
DialogMenu dialogMenu = new DialogMenu();
dialogMenu.show(getSupportFragmentManager(),"Example dialog");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment