小编use*_*519的帖子

onClick方法不起作用

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play);
    gl = (GridLayout) findViewById(R.id.grid);
    array = new Button[7][6];
    Button btn;
    for(int i=0; i<7; i++)
    {
        for(int j=0; j<6; j++)
        {
            btn = new Button(this);
            btn.setId(7*i + j + 1);
            array[i][j] = btn;
            gl.addView(btn);
        }
    }
    turn = 0;
    Toast.makeText(this, "Test", Toast.LENGTH_SHORT).show();                

}

@Override
public void onClick(View v) 
{
    Toast.makeText(this, "Test1", Toast.LENGTH_SHORT).show();               
    if(v instanceof Button)
    {
        Toast.makeText(this, "Test2", Toast.LENGTH_SHORT).show();
        int[] d = GetCellByID(v.getId());
        Button b = (Button)v;
        b.setEnabled(false);
        if(turn == 0)
        {
            b.setBackgroundColor(Color.YELLOW);
            turn …
Run Code Online (Sandbox Code Playgroud)

java eclipse android

3
推荐指数
2
解决办法
132
查看次数

标签 统计

android ×1

eclipse ×1

java ×1