public class ButtonGridFragment
extends Fragment
Exercise
.Modifier and Type | Class and Description |
---|---|
static interface |
ButtonGridFragment.AnswerSelectedListener
Listener interface for Button clicks, any Activity that attaches this Fragment must implement this.
|
class |
ButtonGridFragment.GridButtonClickListener
Listener class for ButtonGridAdapter click events.
|
Modifier and Type | Field and Description |
---|---|
private LinearLayout |
base
Basic layout that will contain the
android.widget.TableLayout |
private static int |
COLUMNS
The maximum width of the button grid
|
private static ButtonGridFragment.AnswerSelectedListener |
listener |
private java.util.List<java.lang.String> |
mAnswerList
List of answers to be displayed on the buttons.
|
private Context |
mCtx |
private java.util.List<java.lang.Integer> |
mFadedButtonList
List of buttons that are currently faded out, used for state management
|
private static java.lang.String |
PREFERENCES_MANSWERLIST |
private static java.lang.String |
PREFERENCES_MFADEDBUTTONLIST |
private TableLayout |
tl
TableLayout that will contain as many
android.widget.TableRow children as necessary |
Constructor and Description |
---|
ButtonGridFragment() |
Modifier and Type | Method and Description |
---|---|
private static void |
answerSelected(int position) |
private void |
buildGrid()
Constructs a grid of Button objects from the mAnswerlist field.
|
(package private) void |
clearGrid()
Clear the TableLayout.
|
void |
fadeButton(int position)
Fade out the Button at the given position.
|
void |
initGrid(java.util.List<java.lang.String> answerList)
Build a fresh TableLayout for the given List of Strings.
|
void |
onAttach(Activity activity)
Override to ensure the Activity we are attached to implements
ButtonGridFragment.AnswerSelectedListener |
void |
onCreate(Bundle savedInstanceState) |
View |
onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
On view creation load any saved state and reconstruct the UI how we left it.
|
void |
onSaveInstanceState(Bundle outState) |
void |
resetGridButtonState()
Undo any Alpha and setClickable changes done by fadeButton().
|
private static final java.lang.String PREFERENCES_MFADEDBUTTONLIST
private static final java.lang.String PREFERENCES_MANSWERLIST
private static ButtonGridFragment.AnswerSelectedListener listener
private static final int COLUMNS
private Context mCtx
private LinearLayout base
android.widget.TableLayout
private TableLayout tl
android.widget.TableRow
children as necessaryprivate java.util.List<java.lang.String> mAnswerList
private java.util.List<java.lang.Integer> mFadedButtonList
public void onCreate(Bundle savedInstanceState)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
public void onAttach(Activity activity)
ButtonGridFragment.AnswerSelectedListener
activity
- The activity this fragment is attached to.ButtonGridFragment.AnswerSelectedListener
public void onSaveInstanceState(Bundle outState)
public void initGrid(java.util.List<java.lang.String> answerList)
answerList
- The answers to display on the Buttons.private void buildGrid()
void clearGrid()
private static void answerSelected(int position)
public void fadeButton(int position)
position
- The position of the Button to fade out.public void resetGridButtonState()