Back to project page RaceTimer.
The source code is released under:
GNU General Public License
If you think the Android project RaceTimer 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 com.liamfruzyna.android.racetimer.fragments; //from w w w . j a va2s. c o m import android.app.Fragment; import android.app.FragmentManager; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; import com.liamfruzyna.android.racetimer.AppData; import com.liamfruzyna.android.racetimer.Fab; import com.liamfruzyna.android.racetimer.R; import java.util.ArrayList; import java.util.List; /** * Created by mail929 on 9/13/14. * A Fragment that shows all the teams */ public class HomeFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.teams, container, false); //init view widgets final Fab fab = (Fab) view.findViewById(R.id.fab); ListView teams = (ListView) view.findViewById(R.id.teamsList); //set up fab (Floating Action Button) fab.setFabDrawable(getResources().getDrawable(R.drawable.ic_action_add)); fab.setFabColor(getResources().getColor(R.color.fab_blue)); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //takes you to adda team when clicked Fragment tf = new AddTeamFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, tf).commit(); } }); //creates a list of team names final List<String> savedTeams = new ArrayList<String>(); for(int i = 0; i < AppData.teams.size(); i++) { savedTeams.add(AppData.teams.get(i).name + " (" + AppData.teams.get(i).shortName + ")"); } //listview of teams teams.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, savedTeams) { public View getView(final int position, View convertView, ViewGroup parent) { //basic setup View view; if (convertView == null) { LayoutInflater infl = (LayoutInflater) getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE); convertView = infl.inflate(android.R.layout.simple_list_item_1, parent, false); } view = super.getView(position, convertView, parent); //init textview and add team name TextView text = (TextView) view.findViewById(android.R.id.text1); text.setText(savedTeams.get(position)); return view; } }); //listens for you to choose a team teams.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //goes to that team Fragment tf = new TeamFragment(); Bundle args = new Bundle(); args.putInt("key", i); tf.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, tf).commit(); } }); return view; } }