Pada kesempatan kali ini saya mencoba membuat aplikasi ujian berbasis android. Aplikasi ini saya buat sebagai pengumpulan tugas Ujian Tengah Semester Mobile Programming. 
Aplikasi ujian online ini adalah aplikasi yang bertujuan untuk mempermudah melakukan ujian, yaitu  secara online. Dengan adanya aplikasi ini diharapkan dapat mempermudah pengguna untuk melakukan ujian secara online dan tidak perlu menggunakan alat tulis untuk melakukan pengerjaan. Aplikasi ini saya buat dengan menggunakan Eclipse dan melakukan running aplikasi langsung menggunakan ponsel.
- Membuat file Android Project Baru dengan nama UTSRosya
 - Membuat Activity besrta file Java-nya, diantaranya :
 
- activity_main (login form),
 - activity_welcome (berhasil login),
 - activity_uts (soal ujian),
 - activity_ujian_selesai (cetak nilai)
 
Berikut ini saya sertakan detail xml graphic dan source code .xml beserta source code .java
<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" >
    
<LinearLayout
 android:id="@+id/linearLayout1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_alignParentTop="true"
 android:layout_marginTop="27dp">
 <TextView
     android:id="@+id/textView1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:gravity="center"
     android:text="Silahkan Login"
     android:textAppearance="?android:attr/textAppearanceMedium"
     android:textSize="24sp" 
     android:textStyle="normal|bold" />
</LinearLayout>
   
<LinearLayout
 android:id="@+id/linearLayout2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/linearLayout1"
 android:orientation="vertical"
 android:layout_marginTop="57dp">
 
 <TextView
  android:id="@+id/textView2"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="User Name"/>
 <EditText
     android:id="@+id/username"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<LinearLayout
 android:id="@+id/linearLayout3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/linearLayout2"
 android:orientation="vertical">
 <TextView
  android:id="@+id/textView3"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="Password"/>
 <EditText
     android:id="@+id/password"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:inputType="textPassword" />
 
</LinearLayout>
<LinearLayout
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_below="@+id/linearLayout3">
 <Button
     android:id="@+id/btnLogin"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_marginTop="67dp"
     android:layout_weight="3"
     android:text="Login" />
</LinearLayout>
</RelativeLayout>
Berikut adalah graphical layout dari activity_main.xml
- activity_welcome.xml
 
<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=".Welcome" >
<LinearLayout
 android:id="@+id/linearLayout1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_alignParentTop="true">
    <TextView
        android:text="Selamat Datang"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="27dp"
        android:id="@+id/textView"
        android:textAlignment="center"
        android:gravity="center"
        android:textSize="30sp"
        android:textStyle="normal|bold" 
        android:textAppearance="?android:attr/textAppearanceMedium" />
    
</LinearLayout>
<TextView
        android:text="Ujian Tengah Semester"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView4"
        android:layout_below="@+id/textView3"
        android:textAlignment="center"
        android:gravity="center"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="70dp"
        android:textSize="18sp" />
<TextView
        android:text="Silahkan tekan tombol MULAI untuk mulai Ujian."
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView4"
        android:layout_below="@+id/textView3"
        android:textAlignment="center"
        android:gravity="center"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="170dp"
        android:textSize="18sp" />
<TextView
        android:text="Selamat Mengerjakan !!!"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="normal|bold"
        android:id="@+id/textView4"
        android:layout_below="@+id/textView3"
        android:textAlignment="center"
        android:gravity="center"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="300dp"
        android:textSize="18sp" />
<Button
    android:id="@+id/btnMulai"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="410dp"
    android:text="MULAI" >
     
</Button>
</RelativeLayout>
- activity_uts.xml
 
<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=".UTS" >
      <TextView
         android:id="@+id/textView1"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="10dp"
         android:text="TextView"
         android:textSize="18sp" />
    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_marginTop="60dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="RadioButton" />
        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />
        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />
        
        <RadioButton
            android:id="@+id/radio3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton" />
    </RadioGroup>
    
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="200dp"
    android:orientation="horizontal" >
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Kembali" 
        />
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Selanjutnya" 
        />
    </LinearLayout>
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    
    <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="380dp"
        android:text="Selesai" />
    </LinearLayout>
</RelativeLayout>
- activity_ujian_selesai.xml
 
<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=".UjianSelesai" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="70dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="400dp"
        android:text="Keluar" />
</RelativeLayout>
Berikut graphical layout dari activity_ujian_selesai.xml
Setelah selesai dengan activity, kita lanjutkan dengan source code .java
- MainActivity.java
 
package com.tugas.utsrosya;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
//public class MainActivity extends Activity {
 public class MainActivity extends Activity {
     EditText username, password;
     Button btnLogin;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  username = (EditText) findViewById(R.id.username);
        password = (EditText) findViewById(R.id.password);
        btnLogin = (Button)findViewById(R.id.btnLogin);
 
 btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String usernameKey = username.getText().toString();
            String passwordKey = password.getText().toString();
            if (usernameKey.equals("161011400074") && passwordKey.equals("123456")){
                //jika login berhasil
                Toast.makeText(getApplicationContext(), "LOGIN SUKSES",
                        Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(MainActivity.this, Welcome.class);
                MainActivity.this.startActivity(intent);
                finish();
            }else {
                //jika login gagal
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setMessage("Username atau Password Anda salah!")
                        .setNegativeButton("Retry", null).create().show();
            }
        }
    });
}
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }
}
- Welcome.java
 
package com.tugas.utsrosya;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Welcome extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_welcome);
   Button btnMulai=(Button)findViewById(R.id.btnMulai);
         //CQuiz=(Button)findViewById(R.id.button2);
         btnMulai.setOnClickListener(new OnClickListener() {
    @Override 
    public void onClick(View v) {
          Intent intent=new Intent(Welcome.this,UTS.class);
          startActivity(intent);
          finish();
    }
   });
  }  
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_welcome, menu);
  return true;
 }
}
- UTS.Java
 
import android.os.Bundle;
import android.app.Activity;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class UTS extends Activity {
 Button selanjutnya,kembali,selesai;
 RadioGroup rg;
 RadioButton rb1,rb2,rb3,rb4;
 TextView setque;
 int index=0;
 String MyCAns,UserCAns="";
 int totalCurrect,totalQues=10,totalSkeep,totalWrrong;
 ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
 HashMap<String, String> map;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uts);
    
    kembali=(Button)findViewById(R.id.button1);
    selanjutnya=(Button)findViewById(R.id.button2);
    selesai=(Button)findViewById(R.id.button3);
    rg=(RadioGroup)findViewById(R.id.radioGroup1);
    rb1=(RadioButton)findViewById(R.id.radio0);
    rb2=(RadioButton)findViewById(R.id.radio1);
    rb3=(RadioButton)findViewById(R.id.radio2);
    rb4=(RadioButton)findViewById(R.id.radio3);
    rb1.setChecked(false);
    rb2.setChecked(false);
    rb3.setChecked(false);
    rb4.setChecked(false);
   
    setque=(TextView)findViewById(R.id.textView1);
    kembali.setVisibility(View.GONE);
    selesai.setVisibility(View.GONE);
    set_Your_Ques();
    set_Ques_One();
    rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
     
  @Override
  public void onCheckedChanged(RadioGroup group, int checkedId) {
     RadioButton rb=(RadioButton)findViewById(checkedId) ;
     UserCAns=rb.getText().toString().trim();
  }
 });
    
    kembali.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
  if(UserCAns.equals("")){
      totalSkeep++;
     }else if(UserCAns.equals(MyCAns)){
      totalCurrect++;
     }else{
      totalWrrong++;
     }
     UserCAns="";
     rb1.setChecked(false);
        rb2.setChecked(false);
        rb3.setChecked(false);
        rb4.setChecked(false);
        back();
    }
    });  
   
    selanjutnya.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
  
 kembali.setVisibility(View.VISIBLE);
    if(UserCAns.equals("")){
  totalSkeep++;
 }else if(UserCAns.equals(MyCAns)){
  totalCurrect++;
 }else{
  totalWrrong++;
 }
 UserCAns="";
 rb1.setChecked(false);
    rb2.setChecked(false);
    rb3.setChecked(false);
    rb4.setChecked(false);
    next();
 }
    });
   
    selesai.setOnClickListener(new OnClickListener() {
     
 @Override
 public void onClick(View v) {
 Intent intent=new Intent(UTS.this,UjianSelesai.class);
 intent.putExtra("totalquestion", "Total Pertanyaan : "+totalQues);
 intent.putExtra("totalcurrect", "Total Nilai : "+totalCurrect);
 intent.putExtra("totalSkeep", "Total Dilewati : "+totalSkeep);
 intent.putExtra("totalWrrong", "Total Salah : "+totalWrrong);
 startActivity(intent);
 finish();
  
 }
    });
}
    
    private void set_Ques_One() {
  map=MyArrList.get(index);
  setque.setText(map.get("Ques").toString().trim());
  rb1.setText(map.get("A1").toString().trim());
  rb2.setText(map.get("A2").toString().trim());
  rb3.setText(map.get("A3").toString().trim());
  rb4.setText(map.get("A4").toString().trim());
  MyCAns=map.get("CA1").toString().trim();
  //Toast.makeText(getApplicationContext(),"1"+index,2000).show();
 }
 public void next() {
     if(index==9){
  kembali.setVisibility(View.GONE);
  selanjutnya.setVisibility(View.GONE);
  selesai.setVisibility(View.VISIBLE);
  }else{
  index++;
  //Toast.makeText(getApplicationContext(),""+index,2000).show(); 
  map=MyArrList.get(index);
  setque.setText(map.get("Ques").toString().trim());
  rb1.setText(map.get("A1").toString().trim());
  rb2.setText(map.get("A2").toString().trim());
  rb3.setText(map.get("A3").toString().trim());
  rb4.setText(map.get("A4").toString().trim());
  MyCAns=map.get("CA1").toString().trim();
  }
 }
    public void back() {
     if(index==0){
  kembali.setVisibility(View.GONE);
  selesai.setVisibility(View.GONE);
     }else{
     index--;
     map=MyArrList.get(index);
  setque.setText(map.get("Ques").toString().trim());
  rb1.setText(map.get("A1").toString().trim());
  rb2.setText(map.get("A2").toString().trim());
  rb3.setText(map.get("A3").toString().trim());
  rb4.setText(map.get("A4").toString().trim());
  MyCAns=map.get("CA1").toString().trim();
             }  
 }
    public void set_Your_Ques() {
     //Q 1
     map=new HashMap<String, String>();
  map.put("Ques", "1. Method yang digunakan untuk mengkonversi nilai string ke integer dalam Java adalah ?");
  map.put("A1", "parseInt()");
  map.put("A2", "converseInt()");
  map.put("A3", "Cint()");
  map.put("A4", "ChangeInt()");
  map.put("CA1","parseInt()");
  MyArrList.add(map);
  //Q 2
     map=new HashMap<String, String>();
  map.put("Ques", "2. Software yang digunakan dalam pengembangan Android adalah ?");
  map.put("A1", "Android Studio");
  map.put("A2", "Androi Virtual Device Manager");
  map.put("A3", "Standart Development Kit Manager");
  map.put("A4", "Semua jawaban benar");
  map.put("CA1","Semua jawaban benar");
  MyArrList.add(map);
  //Q 3
     map=new HashMap<String, String>();
  map.put("Ques", "3. Bahasa pemrograman android berbasis ?");
  map.put("A1", "Java");
  map.put("A2", "PHP");
  map.put("A3", "C++");
  map.put("A4", "Semua jawaban benar");
  map.put("CA1","Java");
  MyArrList.add(map);
  //Q 4
     map=new HashMap<String, String>();
  map.put("Ques", "4. Android tidak bisa dikembangkan pada komputer dengan sistem operasi ?");
  map.put("A1", "Windows XP");
  map.put("A2", "DOS");
  map.put("A3", "Red Hat");
  map.put("A4", "Semua jawaban benar");
  map.put("CA1","DOS");
  MyArrList.add(map);
  //Q 5
     map=new HashMap<String, String>();
  map.put("Ques", "5. Contoh brainware adalah ?");
  map.put("A1", "Programmer");
  map.put("A2", "Laptop");
  map.put("A3", "Android Studio");
  map.put("A4", "Semua jawaban benar");
  map.put("CA1","Programmer");
  MyArrList.add(map);
  //Q6
     map=new HashMap<String, String>();
  map.put("Ques", "6. Pemilik dari Android saat ini adalah ?");
  map.put("A1", "Android inc.");
  map.put("A2", "Google inc.");
  map.put("A3", "HTC");
  map.put("A4", "Semua jawaban benar");
  map.put("CA1","Google inc.");
  MyArrList.add(map);
  //Q7
     map=new HashMap<String, String>();
  map.put("Ques", "7. Berikut ini adalah keyword yang terdapat dalam Java, kecuali ?");
  map.put("A1", "Goto");
  map.put("A2", "Break");
  map.put("A3", "If");
  map.put("A4", "String");
  map.put("CA1","String");
  MyArrList.add(map);
  //Q8
     map=new HashMap<String, String>();
  map.put("Ques", "8. Komentar program dalam java dapat menggunakan perintah ?");
  map.put("A1", "/*...*/ saja");
  map.put("A2", "// saja");
  map.put("A3", "// dan /*...*/");
  map.put("A4", "#, // dan /*...*/");
  map.put("CA1","// dan /*...*/");
  MyArrList.add(map);
  //Q9
     map=new HashMap<String, String>();
  map.put("Ques", "9. Berikut ini adalah hak akses yang dapat ditambahkan didepan method Java, kecuali ?");
  map.put("A1", "Static");
  map.put("A2", "Public");
  map.put("A3", "Private");
  map.put("A4", "Protected");
  map.put("CA1","Static");
  MyArrList.add(map);
  //Q10
     map=new HashMap<String, String>();
  map.put("Ques", "10. Method yang digunakan untuk mengubah panjang data StringBuffer adalah ?");
  map.put("A1", "length()");
  map.put("A2", "setLength()");
  map.put("A3", "Changelength()");
  map.put("A4", "reverse()");
  map.put("CA1","setLength()");
  MyArrList.add(map);
 }
}
- UjianSelesai.java
 
package com.tugas.utsrosya;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class UjianSelesai extends Activity {
    TextView t1,t2,t3,t4;
 Button b1;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ujian_selesai);
        t1=(TextView)findViewById(R.id.textView1);
        t2=(TextView)findViewById(R.id.textView2);
        t3=(TextView)findViewById(R.id.textView3);
        t4=(TextView)findViewById(R.id.textView4);
        b1=(Button)findViewById(R.id.button1);
        t1.setText(getIntent().getExtras().getString("totalquestion"));
        t2.setText(getIntent().getExtras().getString("totalcurrect"));
        t3.setText(getIntent().getExtras().getString("totalSkeep"));
        t4.setText(getIntent().getExtras().getString("totalWrrong"));
        b1.setOnClickListener(new OnClickListener() {
   @Override
     public void onClick(View v) {
           Intent intent=new Intent(UjianSelesai.this,MainActivity.class);
           startActivity(intent); 
           finish();
  }
  });
    }
}
Setelah source code .xml dan .java selesai, selanjutnya kita edit 
konfigurasi AndroidManifest.xml seperti berikut.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tugas.utsrosya"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.tugas.utsrosya.MainActivity"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize|stateVisible" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.tugas.utsrosya.Welcome"
            android:label="@string/title_activity_welcome" >
        </activity>
        <activity
            android:name="com.tugas.utsrosya.UTS"
            android:label="@string/title_activity_uts" >
        </activity>
        <activity
            android:name="com.tugas.utsrosya.UjianSelesai"
            android:label="@string/title_activity_ujian_selesai" >
        </activity>
    </application>
</manifest>
Berikut tampilan ketika aplikasi telah di running dan terinstal 
Wassalamu'alaikum Warahmatullahi Wabarakatuh








izin sedot gan, lagi nyari referensi nih, oh ya perkenalkan nama saya Yuli Suseno dari kampus ISB Atma Luhur. terima kasih
BalasHapus