title: how to Listview Refresh after Delete an item on Button Click event in android?
body: <p>I want to delete an item from Listview, and at a time Refresh Listview after deleting an item. How to possible?</p>
  
  <p>I am using get all item using JSON Parsing from database and delete an selected an item on click of button. delete successfully from database but Listview not refresh at a time. how to do?</p>
  
  <p>I am using Json Parsing. not local database.</p>
  
  <p>In This case, How to refresh Listview when Deleting Item?
  please Guide me.
  Thanks in Advance.</p>
  
  <p>My Code is,
  Detail.java File</p>
  
  <pre><code>public class Detail extends Activity {
      ListView lstDetail = null;
      /** String */
      String urlGetDetailData = null;
  
      /** Declare another variable for Listview */
      Adapter1 adapter1 = null;
      ArrayList&lt;Detail&gt; myList = new ArrayList&lt;Detail&gt;();
      /** Hashmap for ListView */
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; dataList = null;
  
      /** JSON Node names */
      public static final String TAG_MEMBER_ID = "mem_id";
      public static final String TAG_ID = "id";
      public static final String TAG_USER_ID = "userid";
      public static final String TAG_STATUS = "Status";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          onCreateActivity(R.layout.detail);
  
          initializeWidgets();
      }
  
      private void initializeWidgets() {
          /** ListView */
          lstDetail = (ListView) findViewById(R.id.lstDetail);
  
          urlGetDetailData = "http://example.com/getdata.php?id="
                  + strId;
  
          new GetDetailData().execute();
          myList.remove(position);
          Adapter1.this.notifyDataSetChanged();
  
      }
  
      /**
       * Async task class to get json by making HTTP call
       * */
      private class GetDetailData extends AsyncTask&lt;Void, Void, Void&gt; {
          JSONObject jsonobject;
          JSONArray jsonarray;
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              dataList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
              // Retrieve JSON Objects from the given URL address
              jsonobject = JSONFunctions.getJSONfromURL(urlGetDetailData);
  
              try {
                  // Locate the array name in JSON
                  jsonarray = jsonobject.getJSONArray("data");
  
                  for (int i = 0; i &lt; jsonarray.length(); i++) {
  
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                      jsonobject = jsonarray.getJSONObject(i);
                      // Retrive JSON Objects
  
                      map.put("mem_id", String.valueOf(jsonobject
                              .getString(TAG_MEMBER_ID)));
                      map.put("id",
                              jsonobject.getString(TAG_ID));
  
                      map.put("userid", jsonobject.getString(TAG_USER_ID));
                      map.put("Status", jsonobject.getString(TAG_STATUS));
  
                      dataList.add(map);
                  }
              } catch (JSONException e) {
                  Log.e("Error", e.getMessage());
                  e.printStackTrace();
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
              if (dataList.size() != 0) {
                  lstDetail.setVisibility(View.VISIBLE);
                  Adapter1 = new Adapter1(Detail.this,
                          dataList);
                  lstDetail.setAdapter(Adapter1);
              } else {
                  lstDetail.setVisibility(View.GONE);
              }
          }
      }
  }
  </code></pre>
  
  <p>And Adapter Class is,
  Adapter1.java File</p>
  
  <pre><code>public class Adapter1 extends BaseAdapter {
      public ArrayList&lt;HashMap&lt;String, String&gt;&gt; arrData = null;
      Context context = null;
      LayoutInflater layoutInflater = null;
      HashMap&lt;String, String&gt; getDetailData = new HashMap&lt;String, String&gt;();
  
      /** String */
      String strMemberId = null, urlDelete = null;
  
      /** Constructor */
      public Adapter1(Context context,
              ArrayList&lt;HashMap&lt;String, String&gt;&gt; arrData) {
          layoutInflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          this.context = context;
          this.arrData  = arrData;
      }
  
      @Override
      public int getCount() {
          return arrData.size();
      }
  
      @Override
      public Object getItem(int position) {
          return arrData.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          ViewHolder viewHolder = null;
          if (convertView == null) {
              convertView = layoutInflater.inflate(
                      R.layout.list_item, null);
  
              viewHolder = new ViewHolder();
              getData = arrData.get(position);
  
              /** Initialize Widgets */
  
              viewHolder.imgCancel = (ImageView) convertView
                      .findViewById(R.id.imgCancel);
  
              viewHolder.imgCancel
                      .setOnClickListener(new OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              strMemberId = arrData.get(
                                      position).get(
                                      Detail.TAG_MEMBER_ID);
                              urlDelete = "http://example.com/delete.php?mem_id="
                                      + strMemberId;
                              new DeleteComments().execute();
                          }
                      });
  
              /** TextView */
              viewHolder.txtMemberId = (TextView) convertView
                      .findViewById(R.id.txtMemberId);
              viewHolder.txtId = (TextView) convertView
                      .findViewById(R.id.txtId);
  
              viewHolder.txtDesc = (TextView) convertView
                      .findViewById(R.id.txtDesc);
  
              /** Set Value */
  
  
              viewHolder.txtMemberId.setText(getDetailData 
                      .get(Detail.TAG_MEMBER_ID));
              viewHolder.txtId.setText(getDetailData
                      .get(Detail.TAG_ID));
  
              viewHolder.txtDesc.setText(getDetailData
                      .get(Detail.TAG_STATUS));
  
              convertView.setTag(viewHolder);
  
          } else {
              viewHolder = (ViewHolder) convertView.getTag();
          }
          return convertView;
      }
  
      /** ViewHolder Class */
      @SuppressLint("NewApi")
      public static class ViewHolder {
          ImageView imgCancel = null;
          TextView txtMemberId = null, txtId = null,txtDesc = null;
      }
  
      public class DeleteComments extends AsyncTask&lt;Void, Void, Void&gt; {
          protected void onPreExecute() {
              super.onPreExecute();
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              ServiceHandler sh = new ServiceHandler();
              String jsonStr = sh.makeServiceCall(urlDelete,
                      ServiceHandler.GET);
              Log.d("Response : delete join comments", "&gt;" + jsonStr);
  
              return null;
          }
  
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
  
          };
      }
  }
  </code></pre>
  
  <p>detail.xml File is,</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/re/android"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" &gt;
  
      &lt;ListView
          android:id="@+id/lstDetail"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>list_item.xml file is,</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/re/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;LinearLayout
          android:id="@+id/contentLayout"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_vertical"
          android:orientation="vertical" &gt;
  
          &lt;TextView
              android:id="@+id/txtId"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="111" /&gt;
  
          &lt;TextView
              android:id="@+id/txtDesc"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ImageView
          android:id="@+id/imgCancel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_centerVertical="true"
          android:src="@drawable/cancel" /&gt;
  
      &lt;TextView
          android:id="@+id/txtMemberId"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBaseline="@+id/txtUserEventId"
          android:layout_alignBottom="@+id/txtUserEventId"
          android:layout_alignParentLeft="true"
          android:text="222" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>