如何在按下按钮之前停止应用程序?

时间:2014-07-22 20:03:01

标签: wait

首先抱歉我的英文! =) 我正在为Android做卡片游戏,我有一些麻烦或问题更好说。 我试过这段代码来实现一个ActionListener到我的ImageButtons(卡片) 但我需要我的应用程序等待,直到某些卡被按下。我以为使用线程,但我不知道如何在我的应用程序中做。谁能帮我? 让我的代码在下面的

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_juego);
        ll = (LinearLayout)findViewById(R.id.ll);
        this.cartaenmesa = (ImageView)findViewById(R.id.imageView1);
        this.numcartasbaraja = (TextView)findViewById(R.id.textView1);
        this.numbar =2;
        this.numcartas = 20;
        this.numjug = 3;
        for(int i=0;i<=this.numjug-1;i++){
            this.jugadores.add(new Jugador("Jugador "+ i));

        }

        this.pilaInicial();
        this.desordenarPila();
        this.repartirInicial();
//      this.DibujarCartaEnMesa(this.pila.get(0));
//      this.DibujarCartas(this.jugadores.get(0).DevolverCartas());
//      this.numcartasbaraja.setText(""+this.pila.size());

        this.iniciarJuego();
    }

这是将Listeners设置为所有按钮的循环。

for (int i = 0; i < this.imgbt_cartas_act.size();i++){
                    this.imgbt_cartas_act.get(i).setOnClickListener(listener); // AGREGAMOS LOS LISTENERS A CADA BOTON
                }

这是我为按钮分配图像和ID的地方

private void DibujarCartas (ArrayList<Carta> c){
        int i = 0;
        for (Carta c1 : c){
            this.imgbt_cartas_act.add(i, new ImageButton(Juego.this));
            //OROS
            if (c1.getValor()== 1 && c1.getPalo()=="Oros"){
                this.imgbt_cartas_act.get(i).setImageResource(R.drawable.oros_1);
                this.imgbt_cartas_act.get(i).setId(1);
            }
            if (c1.getValor()== 2 && c1.getPalo()=="Oros"){
                this.imgbt_cartas_act.get(i).setImageResource(R.drawable.oros_2);
                this.imgbt_cartas_act.get(i).setId(2);
            }
.......
}

最后是OnClick

OnClickListener listener = new OnClickListener() {
    public void onClick(View v) {
        //OROS
        if (v.getId()==1){ // 1 de oros
            carteleg = new Carta(1,"Oros");
        }
        if (v.getId()==2){ // 1 de oros
            carteleg = new Carta(2,"Oros");
        }
        if (v.getId()==3){ // 1 de oros
            carteleg = new Carta(3,"Oros");
        }
        if (v.getId()==4){ // 1 de oros
            carteleg = new Carta(4,"Oros");
        }
.....
    }
  };

0 个答案:

没有答案
相关问题