private void showInvitations() { GridLayout.Spec row; GridLayout.Spec column; GridLayout.LayoutParams params; for (Invitation i : invitations) { final TextView tempText = new TextView(getApplicationContext()); tempText.setText(i.getNomFoyer()); tempText.setTextSize(18); row = GridLayout.spec(mainLayout.getRowCount()); column = GridLayout.spec(0); params = new GridLayout.LayoutParams(row, column); params.setGravity(Gravity.FILL_HORIZONTAL); tempText.setLayoutParams(params); mainLayout.addView(tempText); Button tempAcceptButton = new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall); tempAcceptButton.setText(R.string.show_invitations_accept); column = GridLayout.spec(1); params = new GridLayout.LayoutParams(row, column); tempAcceptButton.setLayoutParams(params); tempAcceptButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { accept(tempText.getText().toString(), mainLayout.getFocusedChild()); } }); mainLayout.addView(tempAcceptButton); Button tempRefuseButton = new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall); tempRefuseButton.setText(R.string.show_invitations_refuse); column = GridLayout.spec(2); params = new GridLayout.LayoutParams(row, column); tempRefuseButton.setLayoutParams(params); tempRefuseButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { refuse(tempText.getText().toString(), mainLayout.getFocusedChild()); } }); mainLayout.addView(tempRefuseButton); } }
public void create() { int width = display.getWidth(); int height = display.getHeight(); board = (GridLayout) activity.findViewById(com.example.wertalp.battleship.R.id.board); board.removeAllViews(); Button buttonSet = (Button) activity.findViewById(com.example.wertalp.battleship.R.id.button23); EditText edit1 = (EditText) activity.findViewById(com.example.wertalp.battleship.R.id.editText); // board.setColumnCount(Integer.parseInt(edit1.getText().toString())); // board.setRowCount(Integer.parseInt(edit1.getText().toString())); board.setColumnCount(10); board.setRowCount(10); laenge = (int) (this.getWidth() - 300) / board.getColumnCount(); breite = laenge; for (int i = 0; i <= board.getRowCount() - 1; i++) { for (int j = 0; j <= board.getColumnCount() - 1; j++) { CellButton button = new CellButton(activity); button.setBackgroundResource(com.example.wertalp.battleship.R.drawable.rectangle); button.setId(i + j); button.setyField(j); button.setxField(i); // button.setText(""+i+j); button.setLayoutParams(new LinearLayout.LayoutParams(laenge, breite)); board.addView(button); // anz++; if (i == 0) { button.setText("" + j); button.setBackgroundResource(com.example.wertalp.battleship.R.drawable.rectangle_second); } if (j == 0) { button.setText("" + i); button.setBackgroundResource(com.example.wertalp.battleship.R.drawable.rectangle_second); } if ((i != 0) && (j != 0)) { // button.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // CellButton b = (CellButton) v; // Toast.makeText(getActivity().getBaseContext(), "" + b.getPositionText(), // Toast.LENGTH_SHORT).show(); // b.setBackgroundResource(com.example.wertalp.battleship.R.drawable.cross); // Butty = b; // Ship cur_Ship = new Ship(board); // show_popup(b); // } // }) ; } ; } } // create Methode ende } // End Create