Search code examples
androidandroid-listviewandroid-2.2-froyoandroid-listfragment

update ListFragment


I have crated a class which extends the ListFragment. I have one button in a layout too , when i click over that button , i am deleting data of listvew , and firing the notifyDataSetChanged of adapter , but ListViewFragment doesn't get updated.

so how can i update the ListFragment ? i am using Android Compatibility Support Package

code inside onActivityCreated

Button addTextTemplateClearBtn  = (Button)  getView().findViewById(R.id.addTextTemplateClearBtn);
addTextTemplateClearBtn.setOnClickListener(  new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            if(templateDB.deleteAllTemplates() !=0)
                Toast.makeText(getActivity(), "All Text Templates Have Been Deleted", Toast.LENGTH_SHORT).show();
                templateAdapter.notifyDataSetChanged();
        }



    });

Solution

  • Awwww , i forgot to clear the List Array which carries the data of listView after templateAdapter.notifyDataSetChanged();

    so after clearing data , it worked !!