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; // w w w. j a v a 2 s . c om import android.app.Fragment; import android.app.FragmentManager; import android.os.Bundle; 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.EditText; import android.widget.ListView; import android.widget.TextView; import com.liamfruzyna.android.racetimer.AppData; import com.liamfruzyna.android.racetimer.R; import java.util.ArrayList; import java.util.List; /** * Created by mail929 on 9/20/14. * A Fragment to create a meet */ public class AddMeetFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.add_meet, container, false); //init view widgets ListView teamsList = (ListView) view.findViewById(R.id.teamsList); final EditText name = (EditText) view.findViewById(R.id.name); final EditText shortName = (EditText) view.findViewById(R.id.shortName); Button finish = (Button) view.findViewById(R.id.done); //create list of team names final List<String> teams = new ArrayList<String>(); for(int i = 0; i < AppData.teams.size(); i++) { teams.add(AppData.teams.get(i).name); } //listview of teams teamsList.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, teams) { 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 and add name to textview TextView tv = (TextView) view.findViewById(android.R.id.text1); tv.setText(teams.get(position)); return view; } }); //listen for a team to be selected teamsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { //if the team hasn't been clicked add it if(view.isEnabled()) { AppData.teams.get(i).meets.add(AppData.meets.size()); } //otherwise remove it else { AppData.teams.get(i).meets.remove(AppData.teams.get(i).meets.size() - 1); } //set it to the opposite of what it was view.setEnabled(!view.isEnabled()); } }); //listen for the finish button to be clicked finish.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //save the meet AppData.addMeet(name.getText().toString(), shortName.getText().toString()); //go to the meet page Fragment tf = new MeetFragment(); Bundle args = new Bundle(); args.putInt("key", AppData.meets.size()-1); tf.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.container, tf).commit(); } }); return view; } }