title: Android ObserveableScrollView to load more (loading issue)
body: <p>I am fetching information from the website in JSON Format and displaying that info into my app using AsynTask. The Problem is that on On First time my Progress dialog shows well and hide after loading contents into app. But When i use Scroll-view to load more then progress dialog appears and hide after loading immediately at the same time progress dialog opens again and not hiding and Scroll-View loads data one more time in the background.I want only one time to load data after each using Scroll-View to load more. Progress Dialog is not hiding and It keeps running my app. I am struck at this point.</p>
  
  <p>Basically i noticed that My Scroll-View indicator collide two times on the bottom due to this scroll-View trigger two times. How can i stop it and restrict this only one time after each scrolling.</p>
  
  <p>And one more thing wanna share that everything is working awesome in Froyo 2.2 and not working in 2.3 to 4.2. Kindly help me on this. Thanks in advance.</p>
  
  <p>Below is my code.</p>
  
  <pre><code>package com.example.lmf;
  
  import java.net.URLEncoder;
  import org.json.JSONArray;
  import org.json.JSONObject;
  
  import com.example.lmf.ObservableScrollView.ScrollViewListener;
  
  import android.app.Activity;
  import android.app.Dialog;
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.Color;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.MenuItem.OnMenuItemClickListener;
  import android.view.View.OnClickListener;
  import android.view.WindowManager;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.LinearLayout.LayoutParams;
  import android.widget.Toast;
  
  public class searchClassified extends Activity implements ScrollViewListener
  {
  
      ObservableScrollView scrollView;
      ProgressDialog _progressDialog;
      int page_no = 1;
      String k = "";
      final static String URL = "http://www.lmf.com.pk/admin/json.php?YOUR URL OF JSON";
      final getInternetData obj = new getInternetData();
      public ImageLoader imageLoader = null;
      Context context = this;
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.get_classified);
          getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
          scrollView = (ObservableScrollView) findViewById(R.id.my_scroll);
          scrollView.setScrollViewListener(this);
          imageLoader = new ImageLoader(this);
          String s = getIntent().getExtras().getString("query")!= "" ? getIntent().getExtras().getString("query") : "";
          EditText et = (EditText) findViewById(R.id.query);
          et.setText(s);
          k = "all="+URLEncoder.encode(s);
          //showProgress(context);
          new getBackgroundData().execute();
  
      }
  
  
  
      public void onScrollEnded(ObservableScrollView scrollView, int x, int y,
              int oldx, int oldy) {
          // TODO Auto-generated method stub
          page_no = page_no + 1;
          k = k+"&amp;page_no="+page_no;
          //showProgress(context);
          getBackgroundData d1 =  new getBackgroundData();
          d1.execute();
          if(d1.getStatus()==AsyncTask.Status.FINISHED) {
              d1 = null;
              _progressDialog.dismiss();
  
          }
  
      }
  
  
      public void searchAds(View v)
      {
  
          EditText query = (EditText) findViewById(R.id.query);
          String q = query.getText().toString();
          if(q == "" || q == "search")
          {
              Dialog d = new Dialog(this);
              d.setTitle("Enter Valid Search Parameter");
              d.show();
          }
          else
          {
              getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
              Intent i = new Intent(searchClassified.this,com.example.lmf.searchClassified.class);
              i.putExtra("query", ""+q+"");
              startActivity(i);
  
          }
  
      }
  
      public void showProgress(Context c)
      {
           _progressDialog = ProgressDialog.show(
                      c,
                      "Please wait",
                      "Performing task..."
                  );
  
      }
  
      public void hideProgress()
      {
          _progressDialog.dismiss();
      }
  
  
  
      //////////// Async Class
  
      private class getBackgroundData extends AsyncTask&lt;Void, Integer, JSONArray&gt;
      {
  
          protected void onPreExecute() 
          {
              _progressDialog = new ProgressDialog(context);
              _progressDialog.setMessage("Loading...");
              _progressDialog.show();
          }
  
          @Override
          protected JSONArray doInBackground(Void... params) 
          {
              try
              {
                  JSONArray array = obj.getDATA(k,URL);
                  return array;
  
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }
                  return null;
          }
  
  
          @Override
          protected void onPostExecute(JSONArray array) 
          {
              LinearLayout sv = (LinearLayout) findViewById(R.id.data);
              try
              {
  
              for (int i = 0; i &lt;array.length(); i++) {
  
  
                  JSONObject row = array.getJSONObject(i);
  
                  //// TextView Creation start here /////////
  
                  TextView tv = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
                  tv.setText(row.getString("post_title"));
                  tv.setTextColor(Color.BLACK);
                  tv.setTextSize(14);
                  tv.setPadding(8, 6, 0, 12);
                  tv.setFocusable(true);
                  tv.setLayoutParams(new LayoutParams(
                          LayoutParams.WRAP_CONTENT,
                          LayoutParams.WRAP_CONTENT));
  
                  //// TextView Creating Ends here /////////
  
  
  
                  //// Horizontal Line Creating here /////////
                  View v = new View(searchClassified.this);
                  LinearLayout.LayoutParams viewLp = new LayoutParams(LayoutParams.MATCH_PARENT, 1);
                  viewLp.setMargins(0, 4, 0, 4);
  
                  v.setLayoutParams(viewLp);
                  v.setBackgroundColor(Color.LTGRAY);
  
                  //// Horizontal Line Creating Ends here /////////
  
  
                  //// Image Creating Starts from  here /////////
  
                  LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  
                  lp.setMargins(3, 0, 15, 8);
  
                  lp.width = 70;
                  lp.height = 80;
                  ImageView imageView = new ImageView(searchClassified.this);
                  String[] parts = row.getString("post_img").split("/");
                  int last_index = parts.length - 1;
                  String image_name = "thumb_"+parts[last_index];
                  String str = "";
                  for(int j=0; j&lt;last_index; j++)
                  {
                      str += parts[j]+"/";
                  }
                  String path = "http://www.lmf.com.pk/"+str+image_name;
  
  
                  imageLoader.DisplayImage(path, imageView);
  
                  //// Image Creating Ends here /////////
  
  
  
                  // Creating LinearLAyout /////////
  
                  LinearLayout l1 = new LinearLayout(searchClassified.this);
  
                  l1.setOrientation(LinearLayout.HORIZONTAL);
                  l1.setHapticFeedbackEnabled(true);
                  l1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                  l1.setId(obj.convertStrtoInt(row.getString("post_id")));
                  l1.setHapticFeedbackEnabled(true);
                  l1.setOnClickListener(new OnClickListener() {
  
                      public void onClick(View v) {
                          // TODO Auto-generated method stub
  
                          Intent i = new Intent(searchClassified.this,com.example.lmf.adsDetail.class);
                          i.putExtra("id", v.getId());
                          startActivity(i);
                      }
                  });
  
                  l1.addView(imageView, lp);
                  l1.addView(tv);
                  sv.addView(l1);
                  sv.addView(v);
  
  
  
              }
  
              _progressDialog.hide();
              _progressDialog.dismiss();
              _progressDialog = null;
              }
              catch(Exception e)
              {
                  e.printStackTrace();
  
              }
  
          }
  
  
  
      }
  
  
  
      /////////// Ends Here 
  
      public boolean onCreateOptionsMenu(Menu menu) 
      {
          MenuItem item = menu.add ("Quit");
          item.setOnMenuItemClickListener (new OnMenuItemClickListener()
          {
              public boolean onMenuItemClick (MenuItem item)
              {
                  //clearArray();
                  finish();
                  return true;
              }
          });
                  return true;
      }
  
  
  }
  </code></pre>