public class MainActivity extends Activity implements View.OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TableLayout layout = new TableLayout (this); layout.setLayoutParams( new TableLayout.LayoutParams(4,5) ); layout.setPadding(1,1,1,1); for (int f=0; f<=13; f++) { TableRow tr = new TableRow(this); for (int c=0; c<=9; c++) { Button b = new Button (this); b.setText(""+f+c); b.setTextSize(10.0f); b.setTextColor(Color.rgb( 100, 200, 200)); b.setOnClickListener(this); tr.addView(b, 30,30); } // for layout.addView(tr); } // for super.setContentView(layout); } // () public void onClick(View view) { ((Button) view).setText("*"); ((Button) view).setEnabled(false); } } // class
layout.setLayoutParams( new TableLayout.LayoutParams(85,85) ); layout.setPadding(8,8,8,8);
TableLayout layout = new TableLayout(this); layout.setLayoutParams(new TableLayout.LayoutParams(4,5)); layout.setPadding(1, 1, 1, 1); for(int i=0; i<7; i++) { TableRow tr = new TableRow(this); for(int j=0; j<6; j++) { Button b = new Button(this); b.setText("0"); b.setOnClickListener(buttonListener); tr.addView(b); } layout.addView(tr); } setContentView(layout); } View.OnClickListener buttonListener = new View.OnClickListener() { public void onClick(View v) { Button btn1 = (Button)v; //thisButton.setText(Integer.toString(Integer.parseInt((String) thisButton.getText()) + 1)); String name = btn1.getText().toString(); } };
public class MainActivity extends Activity implements View.OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TableLayout layout = new TableLayout (this); layout.setLayoutParams( new TableLayout.LayoutParams(4,5) ); layout.setPadding(1,1,1,1); for (int f=0; f<=13; f++) { TableRow tr = new TableRow(this); for (int c=0; c<=9; c++) { Button b = new Button (this); b.setText(""+f+c); b.setTextSize(10.0f); b.setTextColor(Color.rgb( 100, 200, 200)); b.setOnClickListener(this); tr.addView(b, 30,30); } // for layout.addView(tr); } // for super.setContentView(layout); } // () public void onClick(View view) { ((Button) view).setText("*"); ((Button) view).setEnabled(false); } } // class