How to set OnItemClickListener funtion on ListView using CustomAdapter : I have displayed the list of student from the database, field that are displayed are Student_Roll_no, Student_Name and Student_ID. Student_Roll_no and Student_Name are display using TextView and Student_ID id is display with checkbox. Now I want to set the code by which, when I click at the list the checkbox of that particular row should be checked but the listview is not responding to OnItemClickListener function, as there i have make a toast that doesn't appear when i click on the list.

Sry for the bad english

**activity_attendence.xml**

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_attendence"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.tejas.paras.bpibs.Attendence"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/roll"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingBottom="2dip"
            android:paddingTop="6dip"
            android:text="Roll"
            android:layout_weight=".1"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingBottom="2dip"
            android:text="Name"
            android:layout_weight=".6"
            android:textColor="#000000" />

        <TextView
            android:text="Present"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/textView26"
            android:layout_weight=".2"
            android:textColor="#000000" />

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:background="#000000"
            android:layout_height="1dp"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"></LinearLayout>

        <ListView
            android:layout_width="match_parent"
            android:layout_height="375dp"
            android:id="@+id/listview"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:layout_weight="1.10" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:text="Save Attendence"
                android:layout_width="match_parent"
                android:background="@drawable/buttonlayout2"
                android:textColor="#FFFFFF"
                android:layout_height="wrap_content"
                android:id="@+id/button5" />
        </LinearLayout>
    </LinearLayout>
    </LinearLayout>


__Attendence.java__

    package com.tejas.paras.bpibs;

    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.Button;
    import android.widget.ListView;
    import android.widget.Toast;

    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;
    import java.util.ArrayList;
    import java.util.HashMap;

    public class Attendence extends AppCompatActivity{

    String date, course, year,ID;
    String myJSON;

    private static final String TAG_RESULTS = "result";

    String link;
    JSONArray peoples = null;
    BufferedReader bufferedReader;
    String result,data;
    ArrayList<HashMap<String, String>> personList;
    Button b5;
    ListView list,listView;
    private DataModel dataModel;
    private ArrayList<DataModel> dataModels;
    private static CustomAdapter adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_attendence);
        list=(ListView)findViewById(R.id.listview);
        b5=(Button)findViewById(R.id.button5);
       
        getData();

        b5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(Attendence.this,"1."+view, Toast.LENGTH_SHORT).show();
            }
        });


        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> a, View v, int position,
                                    long id) {
                 dataModel = dataModels.get(position);
                Toast.makeText(Attendence.this,"2.1",Toast.LENGTH_LONG).show();
                 ID=dataModel.getID();
                    Toast.makeText(Attendence.this,dataModel.getRoll(),Toast.LENGTH_LONG).show();

            }
        });
    }


    protected void showList() {
        dataModels= new ArrayList<>();
       
        try {

            JSONObject jsonObj = new JSONObject(myJSON);
            peoples = jsonObj.getJSONArray(TAG_RESULTS);

            for (int i = 0; i < peoples.length(); i++) {
                JSONObject c = peoples.getJSONObject(i);

                dataModels.add(new DataModel(c.getString("name"),c.getString("id"),  c.getString("roll")));
            }
            adapter = new CustomAdapter(dataModels, getApplicationContext());
            list.setAdapter(adapter);

        }
        catch (JSONException e) {
            e.printStackTrace();
        }
    }


    public void getData() {
        class GetDataJSON extends AsyncTask<String, Void, String> {

            @Override
            protected String doInBackground(String... params) {

                try {
                    
                    link = "http://painnation.esy.es/attendence.php?date=18022017&course=MCA&year=3";
                    URL url = new URL(link);
                    HttpURLConnection con = (HttpURLConnection) url.openConnection();
                    bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));


                    StringBuilder sb = new StringBuilder();

                    String line = null;
                    while ((line = bufferedReader.readLine()) != null)
                    {
                        sb.append(line + "\n");
                    }
                    result = sb.toString();
                } catch (Exception e) {
                    // Oops
                }
                return result;
            }

            @Override
            protected void onPostExecute(String result) {
                myJSON = result;
                showList();
            }
        }
        GetDataJSON g = new GetDataJSON();
        g.execute();
    }
    }


__item_layout.xml__

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp" >


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".1">

        <TextView
            android:id="@+id/roll"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingBottom="2dip"
            android:paddingTop="6dip"
            android:textStyle="bold"
            android:text="Roll"
            android:layout_weight=".1"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:paddingBottom="2dip"
            android:textStyle="bold"
            android:text="Name"
            android:layout_weight=".6"
            android:textColor="#000000" />

        <CheckBox
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/id"
            android:layout_weight=".15"
            android:textColor="#000000" />

    </LinearLayout>
    </LinearLayout>


__CustomAdapter.java__

    package com.tejas.paras.bpibs;

    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.CheckBox;
    import android.widget.TextView;

    import java.util.ArrayList;


    public class CustomAdapter extends ArrayAdapter<DataModel> implements View.OnClickListener{

    private ArrayList<DataModel> dataSet;
    Context mContext;

    private static class ViewHolder {
        TextView name;
        TextView roll;
        CheckBox id;
    }

    public CustomAdapter(ArrayList<DataModel> data, Context context) {
        super(context, R.layout.item_layout, data);
        this.dataSet = data;
        this.mContext=context;

    }

    @Override
    public void onClick(View v) {

        int position=(Integer) v.getTag();
        Object object= getItem(position);
        DataModel dataModel=(DataModel)object;

    }

    private int lastPosition = -1;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
     
        DataModel dataModel = getItem(position);
       
        ViewHolder viewHolder;

        final View result;

        if (convertView == null) {

            viewHolder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(R.layout.item_layout, parent, false);
            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            viewHolder.roll = (TextView) convertView.findViewById(R.id.roll);
            viewHolder.id=(CheckBox) convertView.findViewById(R.id.id);


            result=convertView;

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            result=convertView;
        }
        lastPosition = position;
        viewHolder.name.setText(dataModel.getName());
        viewHolder.roll.setText(dataModel.getRoll());
        viewHolder.id.setText(dataModel.getID());

        return convertView;
    }
    }

__DataModel.java__

    package com.tejas.paras.bpibs;

    public class DataModel {

    String roll;
    String name;
    String id;

    public DataModel(String name1, String id1, String roll1) {
        this.name=name1;
        this.id=id1;
        this.roll=roll1;
    }

    public String getName() {
        return name;
    }

    public String getID() {
        return id;
    }

    public String getRoll() {
        return roll;
    }
    }

Attendence.php file and the database is hosted on a free hosting web server(Hostinger). you can check the DB output using the 
http://painnation.esy.es/attendence.php?date=18022017&course=MCA&year=3

[Output Screen][1]

Data from server is fetch in json format.plz comment the code to do check the checkbox by clicking listview.

__Thank You__


  [1]: https://i.stack.imgur.com/IEX61.jpg