Java tutorial
/* * Numenta Platform for Intelligent Computing (NuPIC) * Copyright (C) 2015, Numenta, Inc. Unless you have purchased from * Numenta, Inc. a separate commercial license for this software code, the * following terms and conditions apply: * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Affero Public License for more details. * * You should have received a copy of the GNU Affero Public License * along with this program. If not, see http://www.gnu.org/licenses. * * http://numenta.org/licenses/ * */ package com.groksolutions.grok.mobile; import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; /** * Sort Bar Fragment */ public class SortBarFragment extends Fragment implements OnCheckedChangeListener { public interface SortBarListener { public void onSortChanged(int newSortByValue); } private SortBarListener _listener; /** * Sort Bar fragment */ public SortBarFragment() { } /* * (non-Javadoc) * @see android.app.Fragment#onCreateView(android.view.LayoutInflater, * android.view.ViewGroup, android.os.Bundle) */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RadioGroup sortBar = (RadioGroup) inflater.inflate(R.layout.fragment_sort_bar, container, false); sortBar.setOnCheckedChangeListener(this); return sortBar; } /* * (non-Javadoc) * @see android.support.v4.app.Fragment#onAttach(android.app.Activity) */ @Override public void onAttach(Activity activity) { super.onAttach(activity); try { this._listener = (SortBarListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement SortBarListener"); } } /* * (non-Javadoc) * @see android.support.v4.app.Fragment#onDetach() */ @Override public void onDetach() { super.onDetach(); this._listener = null; } /* * (non-Javadoc) * @see * android.widget.RadioGroup.OnCheckedChangeListener#onCheckedChanged(android * .widget.RadioGroup, int) */ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (this._listener != null) { this._listener.onSortChanged(checkedId); } } }