title: List view not refreshing when item is deleted
body: <p>I Have a list view where i have loaded it with json array data. I have minus button to delete row from list. Here the problem is I am able to delete the item but list view is not getting refreshed. The list view gets refreshed once the application is closed or when I go back and navigate to that activity again.</p>
  
  <p>Below is the custom adapter class code:</p>
  
  <pre><code> public class AddPassengerAdapater extends BaseAdapter implements ListAdapter {
  
      private final JSONArray jsonArray;
     ArrayList&lt;String&gt; data;
      Context context;
      JSONObject json_data;
      LayoutInflater inflater;
  
      public AddPassengerAdapater(Context context, JSONArray jsonArray,ArrayList&lt;String&gt; data) {
  
          this.context = context;
          this.jsonArray = jsonArray;
          this.data = data;
  
          String details = SessionManager.getPreferences(context,"splitfare_consumer");
          data = new ArrayList&lt;String&gt;();
          JSONArray jsonarray = null;
          try {
              jsonarray = new JSONArray(details);
              for (int i=0; i &lt; jsonarray.length() ; i++){
                  json_data = jsonarray.getJSONObject(i);
                  data.add(String.valueOf(json_data));
  
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          inflater = LayoutInflater.from(this.context);
      }
  
      @Override public int getCount() {
          if(null==jsonArray)
              return 0;
          else
              return jsonArray.length();
      }
  
  
      @Override public JSONObject getItem(int position) {
          if(null==jsonArray) return null;
          else
              return jsonArray.optJSONObject(position);
      }
  
      @Override public long getItemId(int position) {
          JSONObject jsonObject = getItem(position);
  
          return jsonObject.optLong("id");
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          final MyViewHolder mViewHolder;
          if (convertView == null) {
              convertView = inflater.inflate(R.layout.addpassenger_row_layout, parent, false);
              mViewHolder = new MyViewHolder(convertView);
              convertView.setTag(mViewHolder);
          }
          else {
              mViewHolder = (MyViewHolder) convertView.getTag();
          }
  
  
           json_data = getItem(position);
          try {
              String n =  json_data.getString("name");
              mViewHolder.name.setText(n);
              String nu =  json_data.getString("number");
              mViewHolder.number.setText(nu);
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
  
          mViewHolder.deletelist.setOnClickListener(new View.OnClickListener() {
  
              JSONArray delete_jsonarray;
              JSONObject jsonObject;
              @Override
              public void onClick(View v) {
  
                  String phonenumber = mViewHolder.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&lt;= 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());
  
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
              }
  
          });
  
          return convertView;
      }
  
      private class MyViewHolder {
  
  
          TextView name, number;
          ImageView deletelist;
  
          public MyViewHolder(View item) {
  
              name = (TextView) item.findViewById(R.id.consumername);
              number = (TextView) item.findViewById(R.id.consumer_number);
              deletelist = (ImageView) item.findViewById(R.id.dltconsumer);
  
          }
      }
  
  
  }
  
  Listview activity code:
  
          public class AddPassengerList extends AppCompatActivity {
  
          @BindView(R.id.listview)
          ListView listview;
  
          @BindView(R.id.btn_addmore)
          CustomFontButton btn_addmore;
  
          @BindView(R.id.donebtn)
          CustomFontButton donebtn;
  
          public static final String TAG = "AddPassengerList";
          Activity activity=this;
          Context context = this;
          JSONArray js;
          AddPassengerAdapater adapter;
          LayoutInflater inflater;
          String name ;
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_add_passenger_list);
              ButterKnife.bind(this);
  
               /*Status bar color*/
              Window window = activity.getWindow();
              // clear FLAG_TRANSLUCENT_STATUS flag:
              window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
              // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
              window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
              // finally change the color
              window.setStatusBarColor(ContextCompat.getColor(context,R.color.colorAccent));
  
   String data = SessionManager.getPreferences(context,"splitfare_consumer");
  
              Log.d(TAG,""+data);
  
              ArrayList&lt;String&gt; details= new  ArrayList&lt;String&gt;();
              try {
                  js = new JSONArray(data);
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
             adapter = new AddPassengerAdapater(context,js,details);
              listview.setAdapter(adapter);
  
              btn_addmore.setOnTouchListener(new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      switch (event.getAction()){
                          case MotionEvent.ACTION_DOWN:
  
              btn_addmore.setBackgroundResource(R.drawable.addmorepassengerpressed);
                              break;
                          case MotionEvent.ACTION_UP:
  
              btn_addmore.setBackgroundResource(R.drawable.addmorepassenger);
                              Intent i = new Intent(AddPassengerList.this,AddPassenger.class);
                              startActivity(i);
                              break;
                      }
                      return false;
                  }
              });
  
             }
  
         }
  </code></pre>