Java Code Examples for android.widget.GridLayout#getChildCount()

The following examples show how to use android.widget.GridLayout#getChildCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SaveLoadStateFragment.java    From citra_android with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
  View rootView = inflater.inflate(R.layout.fragment_saveload_state, container, false);

  GridLayout grid = rootView.findViewById(R.id.grid_state_slots);
  for (int childIndex = 0; childIndex < grid.getChildCount(); childIndex++)
  {
    Button button = (Button) grid.getChildAt(childIndex);
    button.setOnClickListener(this);
  }

  // So that item clicked to start this Fragment is no longer the focused item.
  grid.requestFocus();

  return rootView;
}
 
Example 2
Source File: RadioGroupGridLayout.java    From spruce-android with MIT License 5 votes vote down vote up
private void setChildrenOnClickListener(AppCompatRadioButton child) {
    GridLayout parent = (GridLayout) child.getParent();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View v = parent.getChildAt(i);
        if (v instanceof AppCompatRadioButton) {
            if (((RadioButton) v).isChecked()) {
                activeRadioButton = (AppCompatRadioButton) v;
            }
            v.setOnClickListener(this);
        }
    }
}
 
Example 3
Source File: StdGameActivity.java    From Primary with GNU General Public License v3.0 5 votes vote down vote up
private void setColumnCount(GridLayout answerarea, int count) {
    List<View> kids = new ArrayList<>();
    for(int i = 0; i< answerarea.getChildCount(); i++) {
        kids.add(answerarea.getChildAt(i));
    }
    answerarea.removeAllViews();

    answerarea.setColumnCount(count);

    for (View k: kids) {
        k.setLayoutParams(new GridLayout.LayoutParams());
        answerarea.addView(k);
    }
}
 
Example 4
Source File: SortingActivity.java    From Primary with GNU General Public License v3.0 5 votes vote down vote up
private void markSorted() {
    final GridLayout sortArea = findViewById(R.id.sort_area);

    for (int i = 0; i < sortArea.getChildCount() - 1; i++) {
        int num1 = (int) sortArea.getChildAt(i).getTag();
        int num2 = (int) sortArea.getChildAt(i + 1).getTag();
        if (num1 > num2) {
            //sortArea.getChildAt(i).setBackgroundColor(Color.CYAN);
            sortArea.getChildAt(i+1).setBackgroundColor(Color.RED);
            //break;
        }

    }
}
 
Example 5
Source File: SettingsActivity.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public void selectTheme(View view) {
    GridLayout grid = (GridLayout) view.getParent();
    int selection = grid.indexOfChild(view);
    for (int i = 0; i < grid.getChildCount(); i++)
        grid.getChildAt(i).setSelected(false);
    view.setSelected(true);
    selectTheme(selection, true);
}
 
Example 6
Source File: SortingActivity.java    From Primary with GNU General Public License v3.0 4 votes vote down vote up
private void checkDone() {
    if (!problemDone) {
        final GridLayout sortArea = findViewById(R.id.sort_area);

        boolean sorted = true;

        for (int i = 0; i < sortArea.getChildCount() - 1; i++) {
            int num1 = (int) sortArea.getChildAt(i).getTag();
            int num2 = (int) sortArea.getChildAt(i + 1).getTag();
            if (num1 > num2) {
                sorted = false;
                break;
            }

        }
        if (sorted) {
            cancelHint();
            problemDone = true;
            stopTimer();


            for (int i = 0; i < sortArea.getChildCount(); i++) {
                final int c = i;
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        sortArea.getChildAt(c).setBackgroundColor(Color.GREEN);
                    }
                }, (c + 1) * 1000 / sortArea.getChildCount());
            }


            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    finishDone();
                }
            }, 1200);
        }
    }

}
 
Example 7
Source File: ColorGridPreference.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void showDialog(Bundle state) {
    if (getEntryValues() == null) {
        throw new IllegalStateException(
                "ColorGridPreference requires an entryValues array.");
    }

    if (originalValue == null)
        originalValue = getValue();
    final int preselect = findIndexOfValue(getValue());
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
            .setTitle(getDialogTitle())
            .setIcon(getDialogIcon())
            .setCancelable(true)
            .setNegativeButton(android.R.string.cancel, (dialog, which) -> {
                onDialogClosed(false);
                dialog.cancel();
            })
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                onDialogClosed(true);
                dialog.dismiss();
            })
            .setView(R.layout.theme_dialog);
    PreferenceManager pm = getPreferenceManager();
    try {
        Method method = pm.getClass().getDeclaredMethod(
                "registerOnActivityDestroyListener",
                PreferenceManager.OnActivityDestroyListener.class);
        method.setAccessible(true);
        method.invoke(pm, this);
    } catch (Exception e) {
        e.printStackTrace();
    }

    mDialog = builder.create();
    mDialog.setCanceledOnTouchOutside(false);
    mDialog.getWindow().getAttributes().windowAnimations = android.R.anim.accelerate_interpolator;
    if (state != null)
        mDialog.onRestoreInstanceState(state);
    mDialog.show();

    GridLayout gridLayout = mDialog.findViewById(R.id.grid);
    gridLayout.getChildAt(preselect).setSelected(true);
    for (int i = 0; i < gridLayout.getChildCount(); i++) {
        gridLayout.getChildAt(i).setOnClickListener(v -> ((SettingsActivity) getContext()).selectTheme(v));
    }
}