package com.afifzafri.studentsdb;

import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import org.w3c.dom.Text;

public class SearchData extends AppCompatActivity {

    // initialize object
    DBHelper mydb;

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

        mydb = new DBHelper(this);

        final EditText sid = (EditText)findViewById(R.id.editSearch);
        ImageButton btnSearch = (ImageButton)findViewById(R.id.btnSearch);
        final TextView resID = (TextView)findViewById(R.id.resStudID);
        final TextView resName = (TextView)findViewById(R.id.resName);
        final TextView resIC = (TextView)findViewById(R.id.resIC);
        final TextView resDOB = (TextView)findViewById(R.id.resDOB);
        final TextView resAddress = (TextView)findViewById(R.id.resAddress);
        final TextView resProgram = (TextView)findViewById(R.id.resProgram);
        final TextView resPhone = (TextView)findViewById(R.id.resPhone);
        final TextView resEmail = (TextView)findViewById(R.id.resEmail);

        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String studid = sid.getText().toString();

                // access cursor data
                Cursor cursor = mydb.searchData(studid);
                cursor.moveToFirst();
                String name = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_NAME));

                // close cursor
                if (!cursor.isClosed())  {
                    cursor.close();
                }

                resName.setText(name);
            }
        });
    }
}

@@ -1695,245 +1695,1219 @@
 ing 
-name = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_NAME));%0A%0A                // close cursor%0A                if (!cursor.isClosed())  %7B%0A                    cursor.close();%0A                %7D%0A%0A                resName.setText(name
+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                // close cursor%0A                if (!cursor.isClosed())  %7B%0A                    cursor.close();%0A                %7D%0A%0A                //append all the data%0A                resID.setText(id);%0A                resName.setText(name);%0A                resIC.setText(ic);%0A                resDOB.setText(dob);%0A                resAddress.setText(address);%0A                resProgram.setText(program);%0A                resPhone.setText(phone);%0A                resEmail.setText(email
 );%0A 

append all search data result