Back to project page android-shuite-smoking.
The source code is released under:
GNU General Public License
If you think the Android project android-shuite-smoking listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package udl.eps.smokerscontrol; /* w w w .j ava 2 s . com*/ 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.AdapterView; import android.widget.GridView; /** * Created by Marc on 14/12/2014. */ public class MenuFragment extends Fragment{ private GridView gridMenu; private ImageButtonAdapter buttonAdapter; private ButtonListener listener; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_main, container,false); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); gridMenu= (GridView) getView().findViewById(R.id.Buttons_grid); buttonAdapter = addGridButtons(buttonAdapter); gridMenu.setAdapter(buttonAdapter); gridMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { listener.onItemSelected(buttonAdapter.getImageButtonList().get(position).getFragment()); } }); } private ImageButtonAdapter addGridButtons(ImageButtonAdapter buttonAdapter) { buttonAdapter = new ImageButtonAdapter(this.getActivity()); buttonAdapter.addImageButton(new ImageButton(R.drawable.ic_launcher,getResources().getString(R.string.stats),new StatsFragment())); buttonAdapter.addImageButton(new ImageButton(R.drawable.ic_launcher,getResources().getString(R.string.community),new CommunityFragment())); // buttonAdapter.addImageButton(new ImageButton(R.drawable.ic_launcher,getResources().getString(R.string.achievements))); // buttonAdapter.addImageButton(new ImageButton(R.drawable.ic_launcher,getResources().getString(R.string.profile))); // buttonAdapter.addImageButton(new ImageButton(R.drawable.ic_launcher,getResources().getString(R.string.messages))); return buttonAdapter; } @Override public void onAttach(Activity activity) { super.onAttach(activity); try{ listener = (ButtonListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + "must implement ButtonListenner"); } } public interface ButtonListener{ void onItemSelected(Fragment fragment); } public void setButtonListener(ButtonListener b){ this.listener = b; } }