title: android listview loadmore button with xml parsing
body: <p>Hi i have to developed listview with load more button using xml parsing in android application.</p>
  
  <p>Here i have faced some problem.</p>
  
  <p><strong>my xml feed is empty means how can hide the load more button on last page.</strong></p>
  
  <p>i have used below code here.</p>
  
  <pre><code>public class CustomizedListView extends Activity {
  // All static variables
  private String URL = "http://dev.mmm.com/xctesting/xcart444pro/retrieve.php?page=1";
  // XML node keys
  static final String KEY_SONG = "Order"; 
      static final String KEY_TITLE = "orderid";
  static final String KEY_DATE = "date";
  static final String KEY_ARTIST = "payment_method";
      int current_page = 1;
  ListView lv;
  LazyAdapter adapter;
  ProgressDialog pDialog; 
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      lv = (ListView) findViewById(R.id.list);
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; songsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      XMLParser parser = new XMLParser();
      String xml = parser.getXmlFromUrl(URL); // getting XML from URL
      Document doc = parser.getDomElement(xml); // getting DOM element
  
      NodeList nl = doc.getElementsByTagName(KEY_SONG);
      // looping through all song nodes &lt;song&gt;
      for (int i = 0; i &lt; nl.getLength(); i++) {
          // creating new HashMap
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          Element e = (Element) nl.item(i);
          // adding each child node to HashMap key =&gt; value
          map.put(KEY_ID, parser.getValue(e, KEY_ID));
          map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
          map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
                songsList.add(map);
      }
  
      Button btnLoadMore = new Button(this);
      btnLoadMore.setText("Load More");
  
      btnLoadMore.setBackgroundResource(R.drawable.lgnbttn);
      // Adding Load More button to lisview at bottom
      lv.addFooterView(btnLoadMore);
  
      // Getting adapter
      adapter = new LazyAdapter(this, songsList);
      lv.setAdapter(adapter);
                  btnLoadMore.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // Starting a new async task
              new loadMoreListView().execute();
          }
      });
  }
      private class loadMoreListView extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override 
          protected void onPreExecute() {
              // Showing progress dialog before sending http request
              pDialog = new ProgressDialog(
                      CustomizedListView.this);
              pDialog.setMessage("Please wait..");
              //pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.my_progress_indeterminate));
              pDialog.setIndeterminate(true);
              pDialog.setCancelable(false);
              pDialog.show(); 
  
              pDialog.setContentView(R.layout.custom_dialog);
  
  
          }
          protected Void doInBackground(Void... unused) {
  
                      current_page += 1;
  
                      // Next page request
                      URL = "http://dev.mmm.com/xctesting/xcart444pro/retrieve.php?page=" + current_page;
  
                      ArrayList&lt;HashMap&lt;String, String&gt;&gt; songsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
                      XMLParser parser = new XMLParser();
                      String xml = parser.getXmlFromUrl(URL); // getting XML from URL
                      Document doc = parser.getDomElement(xml); // getting DOM element
  
                      NodeList nl = doc.getElementsByTagName(KEY_SONG);
  
  
                      NodeList nl = doc.getElementsByTagName(KEY_SONG);
                      if (nl.getLength() == 0)
                        {
                            btnLoadMore.setVisibility(View.GONE);
                            pDialog.dismiss();
  
                        }
                        else
  
                      // looping through all item nodes &lt;item&gt;
                      for (int i = 0; i &lt; nl.getLength(); i++) {
                          // creating new HashMap
                          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                          Element e = (Element) nl.item(i);
  
                          // adding each child node to HashMap key =&gt; value
                          map.put(KEY_ID, parser.getValue(e, KEY_ID));
                          map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
                          map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
                   songsList.add(map);
                      }
  
                      // get listview current position - used to maintain scroll position
                      int currentPosition = lv.getFirstVisiblePosition();
  
                      // Appending new data to menuItems ArrayList
                      adapter = new LazyAdapter(
                              CustomizedListView.this,
                              songsList);
                      lv.setAdapter(adapter);
               lv.setSelectionFromTop(currentPosition + 1, 0);
  
  
              }
              });
  
              return (null);
          }
  
  
          protected void onPostExecute(Void unused) {
              // closing progress dialog
              pDialog.dismiss();
  
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here i have to run the app means the listview is displayed on perpage 4 items.my last page having 1 item.please refer this screenshot:<a href="http://screencast.com/t/fTl4FETd" rel="nofollow">lastpage</a>
  In last page i have to click the load more button means have to go next activity and <strong>successfully hide the button on empty page</strong>..please refer this screenshot:<a href="http://screencast.com/t/wyG5zdp3r" rel="nofollow">empty page-so hide the button</a></p>
  
  <p>i have to check the condition for empty page:</p>
  
  <pre><code>    if (nl.getLength() == 0)
                      {
                          btnLoadMore.setVisibility(View.GONE);
                          pDialog.dismiss();
  
                      }
  </code></pre>
  
  <p>How can i write the conditon fot last page?????pleas ehelp me</p>
  
  <p>Here <strong>i wish to need the o/p is hide the button on last page</strong>.</p>
  
  <p>Please help me.how can i check the condition.give me some code programmatically.</p>