We unable to scroll the listview till the bottom in the layout after notifyDatasetChanged method in android
<p>I have a problem that, I have many listviews in an single layout and I am using the utility method to showe the data till the bottom of the listview, as:</p>

<pre><code>public class Utility {
        public void setListViewHeightBasedOnChildren(ListView listView) {
            ListAdapter listAdapter = listView.getAdapter();
            if (listAdapter == null) {
                // pre-condition
                return;
            }

            int totalHeight = 0;
            for (int i = 0; i &lt; listAdapter.getCount(); i++) {
                View listItem = listAdapter.getView(i, null, listView);
                listItem.measure(0, 0);
                totalHeight += listItem.getMeasuredHeight();
            }

            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = totalHeight
                    + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
            listView.setLayoutParams(params);
        }
    }
</code></pre>

<p>and It is working fine when we setAdapter to the listView. But when we changed the adapter data through <code>notifyDataSetChanged</code> method of adapter then we can't able to scroll the listview till the bottom and then Utility class failed. How to overcome this problem, please suggest me any solution regardingt the same.</p>

<p>Thanks in advance.</p>

<p><strong>Code:</strong></p>

<pre><code>final ProgressDialog dialog = ProgressDialog.show(
                    ResearchList.this, "Research List       ",
                    "Please wait...   ", true);

            final Handler handler = new Handler() {

                public void handleMessage(Message msg) {

                    // System.out.println("The id after Save:"+id.get(0).toString());

                    // catagory.addAll(keyword_vector1);
                    linear_Category_Child.setVisibility(View.GONE);
                    linear_Category_Child_Child.setVisibility(View.VISIBLE);
                    // tv_Child_Header.setText("Volvo");
                    /*
                     * adapter = new CategoryListLazyAdapter(
                     * ResearchList.this); lvCategory.setAdapter(adapter);
                     */
                    demoAdapterCat.notifyDataSetChanged();
                    Utility util = new Utility();
                    util.setListViewHeightBasedOnChildren(lvCategory);
                    dialog.dismiss();
                }
            };

            final Thread checkUpdate = new Thread() {

                public void run() {
                    try {
                        String sortEncode = URLEncoder.encode("rating");
                        String filterEncode = URLEncoder.encode(filter);
                        String clientEncode = URLEncoder.encode("10030812");
                        String fromEncode = URLEncoder.encode(from);
                        String toEncode = URLEncoder.encode(to);
                        String catUrl = "/v1/vehicles/get-make-models.json?sort="
                                + sortEncode
                                + "&amp;filter="
                                + filterEncode
                                + "&amp;client-id="
                                + clientEncode
                                + "&amp;from="
                                + fromEncode;
                        genSig = new GetSignature(catUrl, "acura");
                        try {
                            signature = genSig.getUrlFromString();
                        } catch (InvalidKeyException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        } catch (NoSuchAlgorithmException e1) {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }
                        // jsonString =
                        // getJsonSring("http://api.highgearmedia.com/v1/vehicles/get-models.json?make=acura&amp;client-id=10030812&amp;signature=LWQbdAlJVxlXZ1VO2mfqAA==");
                        // String signatureEncode =
                        // URLEncoder.encode(signature);
                        String urlEncode = URLEncoder.encode(catUrl
                                + "&amp;signature=" + signature);
                        jsonString = getJsonSring("http://apibeta.highgearmedia.com"
                                + catUrl + "&amp;signature=" + signature);
                        System.out.println("The json category:===&gt;"
                                + jsonString);
                    } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (URISyntaxException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    JsonParse json = new JsonParse(jsonString);
                    json.parseCat();
                    handler.sendEmptyMessage(0);

                }

            };
            checkUpdate.start();
</code></pre>
