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

The following examples show how to use android.widget.GridLayout#getChildAt() . 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: MainActivity.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 6 votes vote down vote up
public void load(){
    saved = this.getSharedPreferences("com.ahmedmaghawry.ahmedezzat2048", Context.MODE_PRIVATE);
    highName = saved.getString("Name", "");
    highScore = saved.getInt("Score", 0);
    TextView highna = (TextView) findViewById(R.id.bestName);
    TextView highnu = (TextView) findViewById(R.id.bestScore);
    highna.setText(highName + "");
    highnu.setText(highScore + "");
    for (int i = 0; i < 16; i++) {
        board.add("");
    }
    int first_index = rand.nextInt(16);
    board.set(first_index, "2");
    GridLayout grid = (GridLayout) findViewById(R.id.grid);
    TextView te = (TextView) grid.getChildAt(first_index);
    te.setText("2");
    drawit();
}
 
Example 2
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 3
Source File: MainActivity.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
private void Generate() {
    if (khalas) {
        int theChoices[] = {2, 2, 2, 4, 2, 2, 2, 4, 2, 2, 4};
        int Chosen = theChoices[rand.nextInt(theChoices.length)];
        int placeIt = rand.nextInt(16);
        if (board.get(placeIt) == "") {
            board.set(placeIt, Chosen + "");
            GridLayout grid = (GridLayout) findViewById(R.id.grid);
            TextView te = (TextView) grid.getChildAt(placeIt);
            te.setText(Chosen + "");
        } else {
            Generate();
        }
    }
}
 
Example 4
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);
        }
    }
}