Back to project page androll.
The source code is released under:
Apache License
If you think the Android project androll 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 me.cybersensei.androll; //from w w w.j a v a2 s .c o m import android.app.Activity; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; public class RollerDialogFragment extends DialogFragment implements View.OnClickListener { public static final String TAG = RollerDialogFragment.class.getCanonicalName(); private RollListener listener; private Spinner sides; private ArrayAdapter<Integer> sidesAdapter; private EditText times; private int position; @Override public void onAttach(Activity activity) { listener = (RollListener) activity; super.onAttach(activity); } //onAttack @Override public void setArguments(Bundle args) { super.setArguments(args); //Get the position position = args.getInt(RollHistoryActivity.SIDES_POSITION_KEY, 0); } //setArguments @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Set title getDialog().setTitle(R.string.roll); //Inflate view View view = inflater.inflate(R.layout.fragment_roller_dialog, container, false); //Create ArrayAdapter sidesAdapter = new ArrayAdapter<Integer>(getActivity(), android.R.layout.simple_spinner_item); sidesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //Fill adapter fillAdapter(); //Get sides sides = (Spinner) view.findViewById(R.id.sp_die_sides); //Set Spinner Adapter sides.setAdapter(sidesAdapter); //Set adapter starting position sides.setSelection(position); //Get times times = (EditText) view.findViewById(R.id.et_rolls); //Set OnClickListener view.findViewById(R.id.b_roll).setOnClickListener(this);; return view; } //onCreateView @Override public void onClick(View v) { switch (v.getId()) { case R.id.b_roll: //Get info and call listener roll(); //Dismiss dialog dismiss(); break; } //switch } //onClick private void fillAdapter() { for (int i = 0; i < Roll.DIE_SIDES.length; i++) { sidesAdapter.add(Roll.DIE_SIDES[i]); } //for } //fillAdapter private int getSides() { return (Integer) sides.getSelectedItem(); } //getSides private int getRolls() { return Integer.parseInt(times.getText().toString()); } //getRolls private void roll() { try { int sides = getSides(); int rolls = getRolls(); listener.newRoll(new Roll(sides, rolls)); } //try catch (Exception e) { //Log.e(TAG, e.getMessage()); if (BuildConfig.DEBUG) e.printStackTrace(); } //catch } //roll } //class RollerDialogFragment