<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:layout_marginBottom="50dip"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#999999"
>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#fff">
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="@+id/txtMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp"
android:layout_x="3px"
android:layout_y="4px"
android:typeface="sans"
android:textColor="#0000ff"
android:background="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever">
</TextView>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView
android:id="@+id/myGambar" android:layout_centerHorizontal="true"
android:src="@drawable/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow android:id="@+id/TableRow00" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="@+id/txtTanya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.Apakah Anda mengalami gejala Pusing2" />
</TableRow>
<RadioGroup
android:id="@+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:text="A. Pilihan A"
android:id="@+id/radA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000">
</RadioButton>
<RadioButton android:text="B. Pilihan B"
android:id="@+id/radB"
android:layout_width="wrap_content"
android:textColor="#000"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton android:text="C. Pilihan C"
android:id="@+id/radC"
android:layout_width="wrap_content"
android:textColor="#000"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton android:text="D. Pilihan D"
android:id="@+id/radD"
android:layout_width="wrap_content"
android:textColor="#000"
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="@+id/txtTanyaKe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pertanyaan ke-1" />
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
soal.java
package com.lp2maray.com;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
public class soal extends Activity {
String sNama="-",sUsia="0",sJK="Laki-laki",sCatatan="";
long starttime = 0;
Timer timer = new Timer();
int jd=0;
String[]arTanya;
String[]arA;
String[]arB;
String[]arC;
String[]arD;
String[]arE;
String[]arBenar;
int ke=0;
int jumbenar=0;
String record="";
TextView txtTanya,txtTanyaKe,txtTimer;
RadioButton radA,radB,radC,radD,radE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal_angka);
Intent i = this.getIntent();
sNama=i.getStringExtra("nama");
sUsia=i.getStringExtra("usia");
sJK=i.getStringExtra("jk");
callSoal();
txtTanya=(TextView)findViewById(R.id.txtTanya);
txtTanyaKe=(TextView)findViewById(R.id.txtTanyaKe);
txtTimer=(TextView)findViewById(R.id.txtTimer);
radA=(RadioButton)findViewById(R.id.radA);
radA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih A",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda A: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda A: Salah\n";}
ke=ke+1;
lihat();
}});
radB=(RadioButton)findViewById(R.id.radB);
radB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih B",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda B: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda B: Salah\n";}
ke=ke+1;
lihat();
}});
radC=(RadioButton)findViewById(R.id.radC);
radC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih C",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda C: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda C: Salah\n";}
ke=ke+1;
lihat();
}});
radD=(RadioButton)findViewById(R.id.radD);
radD.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih D",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda D: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda D: Salah\n";}
ke=ke+1;
lihat();
}});
radE=(RadioButton)findViewById(R.id.radE);
radE.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(soal_angka.this, "Anda memilih E",Toast.LENGTH_LONG).show();
if(arBenar[ke].equalsIgnoreCase("A")){record=record+"Soal No. "+(ke+1)+" Jawaban Anda E: Benar\n";jumbenar=jumbenar+1;}
else{record=record+"Soal No. "+(ke+1)+" Jawaban Anda E: Salah\n";}
ke=ke+1;
lihat();
}});
lihat();
final Handler h = new Handler(new Callback() {
@Override
public boolean handleMessage(Message msg) {
long millis = System.currentTimeMillis() - starttime;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
if (minutes >=0 && seconds >=20){selesai();}
txtTimer.setText(String.format("Waktu Anda ini :"+"%d:%02d"+" (max=> 3:20)", minutes, seconds));
return false;
}
});
class firstTask extends TimerTask {
@Override
public void run() {
h.sendEmptyMessage(0);
}
};
starttime = System.currentTimeMillis();
timer.schedule(new firstTask(), 0,1000);
}
public void selesai(){
new AlertDialog.Builder(this)
.setTitle("Selesai Angka")
.setMessage("Terimakasih... Anda Telah Melakukan tes TPA Angka")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
timer.cancel();
timer.purge();
Intent i= new Intent(soal_angka.this, hasil.class);
i.putExtra("nama", sNama);
i.putExtra("usia", sUsia);
i.putExtra("jk", sJK);
i.putExtra("record", record);
i.putExtra("kategori", "Tes Angka");
i.putExtra("jumbenar", String.valueOf(jumbenar));
startActivity(i);
}})
.show();
}
void lihat(){
if(ke>=jd){selesai();}
else{
txtTanya.setText(" No."+(ke+1)+" "+arTanya[ke]);
radA.setText(arA[ke]);
radB.setText(arB[ke]);
radC.setText(arC[ke]);
radD.setText(arD[ke]);
radE.setText(arE[ke]);
txtTanyaKe.setText(" Pertanyaan ke "+(ke+1)+" dari "+jd +" pertanyaan ");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
void callSoal(){
jd=20;
arTanya=new String[jd];
arA=new String[jd];
arB=new String[jd];
arC=new String[jd];
arD=new String[jd];
arE=new String[jd];
arBenar=new String[jd];
arTanya[0]="19 adalah berapa persennya dari 380 ?";
arA[0]="0,5%";
arB[0]="5%";
arC[0]="0,05%";
arD[0]="0,15%";
arE[0]="5,5%";
arBenar[0]="B";
arTanya[1]="8,0049 : 0,0015";
arA[1]="5336,6";
arB[1]="533,66";
arC[1]="53,366";
arD[1]="53366";
arE[1]="533,55";
arBenar[1]="A";
....
}
}
Tidak ada komentar:
Posting Komentar