If you think the Android project android_app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package models;
/*//fromwww.java2s.com
~ *******************************************************************************
~ Copyright (c) 2013-2014 Daniel Lin, Kamal Chaya, Sean Penney, and Daniel Chuang
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~ *****************************************************************************
*/import com.example.t_danbubbletea.R;
import TabAdapterPackage.ImageAdapter;
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;
publicclass HomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getActivity().setTitle("Home"); // if back button is pressed, re-set title to home
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
rootView.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.image_click)); // animation when enter home page
//set up gridview adapter for pictures and their on click listener
GridView gv1=(GridView)rootView.findViewById(R.id.grid_view);
setAdapter(gv1);
return rootView;
}
privatevoid setAdapter(GridView gview){
gview.setAdapter(new ImageAdapter(getActivity()));
gview.setOnItemClickListener(new OnItemClickListener() {
publicvoid onItemClick(AdapterView<?> parent, View v, int position, long id) {
Fragment newFragment = null;
switch(position){
case 0:
newFragment = new newArrivalFragment();
break;
case 1:
newFragment = new IngredientsFragment();
break;
case 2:
newFragment = new CommentsFragment();
break;
case 3:
newFragment = new aboutUsFragment();
break;
default:
break;
}
if (newFragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, newFragment).commit(); // allow user to go back
// to previous fragment
} else {
// dispaly error message
Log.e("HomeFragment", "Error in creating fragment");
}
}
});
}
}