package com.afifzafri.studentsdb;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class EditViewData extends AppCompatActivity {

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

        Intent intentPage = getIntent();
        String studID = intentPage.getStringExtra("STUD_ID");

        final EditText editStudID = (EditText)findViewById(R.id.editStudID);
        editStudID.setFocusable(false); // disable input
        final EditText editName = (EditText)findViewById(R.id.editName);
        final EditText editIC = (EditText)findViewById(R.id.editIC);
        final EditText editDOB = (EditText)findViewById(R.id.editDOB);
        final EditText editAddress = (EditText)findViewById(R.id.editAddress);
        final EditText editProgram = (EditText)findViewById(R.id.editProgram);
        final EditText editPhone = (EditText)findViewById(R.id.editPhone);
        final EditText editEmail = (EditText)findViewById(R.id.editEmail);

        editStudID.setText(studID);
    }
}

@@ -59,16 +59,48 @@
 Intent;%0A
+import android.database.Cursor;%0A
 import a
@@ -140,16 +140,16 @@
 tivity;%0A
-
 import a
@@ -229,16 +229,45 @@
 extView;
+%0Aimport android.widget.Toast;
 %0A%0Apublic
@@ -315,16 +315,36 @@
 vity %7B%0A%0A
+    DBHelper mydb;%0A%0A
     @Ove
@@ -505,24 +505,127 @@
 iew_data);%0A%0A
+        // initialize object%0A        mydb = new DBHelper(this);%0A%0A        // get intent and data passed%0A
         Inte
@@ -712,24 +712,52 @@
 STUD_ID%22);%0A%0A
+        // initialize input%0A
         fina
@@ -1412,35 +1412,1645 @@
     
-editStudID.setText(studID);
+Cursor cursor = mydb.searchData(studID);%0A        cursor.moveToFirst();%0A%0A        // check if cursor return data or not (data found in db or not)%0A        if(cursor.getCount() %3C 1)%0A        %7B%0A            // show toast message%0A            Toast.makeText(getApplicationContext(), %22No data found%22,Toast.LENGTH_SHORT).show();%0A        %7D%0A        else%0A        %7B%0A            String id = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_ID));%0A            String name = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_NAME));%0A            String ic = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_IC));%0A            String dob = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_DOB));%0A            String address = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_ADDRESS));%0A            String program = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_PROGRAM));%0A            String phone = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_PHONE));%0A            String email = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_EMAIL));%0A%0A            //append all the data%0A            editStudID.setText(id);%0A            editName.setText(name);%0A            editIC.setText(ic);%0A            editDOB.setText(dob);%0A            editAddress.setText(address);%0A            editProgram.setText(program);%0A            editPhone.setText(phone);%0A            editEmail.setText(email);%0A%0A            // show toast message%0A            Toast.makeText(getApplicationContext(), %22Data found%22,Toast.LENGTH_SHORT).show();%0A        %7D%0A%0A        // close cursor%0A        if (!cursor.isClosed())  %7B%0A            cursor.close();%0A        %7D
 %0A   

append search data to update page