when I click on the button for the first click click function doesn't work but for the second time click on-click function works. I don't know what is wrong with my code. Please suggest me right way. Thanks in advance
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { ImageView deletelist = (ImageView) view.findViewById(R.id.dltconsumer); final CustomFontTextView number = (CustomFontTextView) view.findViewById(R.id.consumer_number); deletelist.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONArray delete_jsonarray; JSONObject jsonObject; String phonenumber = number.getText().toString(); String jsonsetpreference_data = SessionManager.getPreferences(context,"splitfare_consumer"); Log.d("jsonsetpreference_data:::::::","" +jsonsetpreference_data); try { delete_jsonarray= new JSONArray(jsonsetpreference_data); for (int i =0; i<= delete_jsonarray.length()-1 ; i++){ jsonObject = delete_jsonarray.getJSONObject(i); String array_phonenumber = jsonObject.getString("number"); if (phonenumber.equals(array_phonenumber)){ delete_jsonarray.remove(i); } } SessionManager.setPreferences(context,"splitfare_consumer",delete_jsonarray.toString()); String data = SessionManager.getPreferences(context,"splitfare_consumer"); Log.d(TAG,""+data); ArrayList<String> details = new ArrayList<String>(); try { js = new JSONArray(data); } catch (JSONException e) { e.printStackTrace(); } adapter = new AddPassengerAdapater(context,js,details); listview.setAdapter(adapter); adapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } } }); } });