Sunday, 17 December 2017

ExpandableListView - notifyDataSetChanged() - Tricky

In general, we use to call the notifyDataSetChanged() method for updating the list view with our new data sets i.e. objects with either array list or any collections. This data set updations made in course of load more or pull to refresh etc.

While using the listview we can simply update the data-set object and call the notifyDataSetChanged() method from the adapter. It will take care the necessary action of updating the listview.  But this will not been happens in the case of ExpandableListView, hence it requires few thread based handling and again need to set the updated adapter to the ExpandableListView.  Please find below the code snippet for the same.

if (dataList.size() > 0) {
 if (!isShowMore) {
  dataListGlobal = dataList;
  dataListExpandableAdapter = new DataListExpandableAdapter(getActivity(), dataListGlobal);
 } else {
  getActivity().runOnUiThread(new Runnable() {
   public void run() {
    if (dataListExpandableAdapter != null) {

Happy Coding :-)

Tuesday, 12 December 2017

Add/Remove View on the Top of Activity or Fragment Android

Add view on to the top of your activity or fragment i.e. in simple to add custom view above the AppCompact/Support Toolbar.

FrameLayout rootLayout = (FrameLayout) findViewById (;
View v = View.inflate(this, R.layout.overlay_layout, rootLayout);

Then when you want to remove it, below use the below code snippet

FrameLayout rootLayout = (FrameLayout)findViewById(;

Happy Coding :-)