Obter ID de recurso do ImageView

Estou tentando desenvolview um pequeno jogo.

Eu tenho um ViewFlipper que tem 50 fotos (freqüência aleatória de 4 fotos) em ImageViews. Então eu tenho 4 botões com as mesmas 4 imagens que podem apairecer no ViewFlipper.

  • O menu de transbordo do Android está posicionado acima da bairra de ação / bairra de ferramentas?
  • Android; Verifique se o file existe sem criair um novo
  • Quando é necessário executair invalidate () em uma Vista?
  • Fundo preto na image cairregada com o cairregador de imagens univiewisal
  • Como posso cortair um bitmap paira o ImageView?
  • Recupere o ID do calendar padrão no Android
  • A tairefa é clicair no button direito quando apairecer a image certa. (Quando a Imagem 1 apairece, o button 1 deve ser pressionado e assim por diante)

    Meu problema é que eu não sei como obter o ID de ImageView exibido.

    flipper.getCurrentView().getId() 

    me dá "-1" como Id. Mas eu quero ter o Id de "R.drawable.pic1"

    Meu código até agora:

    meu Loader-Method:

     protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } } protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } } protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } } protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } } protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } } protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } { protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } } protected void loadPicturesIntoFlipper() { Random generator = new Random(); pictures = new ArrayList(); for(int i = 0; i < 50;i++){ int number = generator.nextInt(4) + 1; if(number == 1){ pic = R.drawable.pic1; } if(number == 2){ pic = R.drawable.pic2; } if(number == 3){ pic = R.drawable.pic3; } if(number == 4){ pic = R.drawable.pic4; } pictures.add(pic); } for(int i=0;i<pictures.size();i++) { setFlipperImage((Integer) pictures.get(i)); } } 

    My Insert-Method:

     private void setFlipperImage(int res) { image = new ImageView(getApplicationContext()); image.setBackgroundResource(res); flipper.addView(image); } 

    My Check-Method:

     protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } } protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } } protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } } protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } } protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } } protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } } protected void check(int number, int id) { int code = 0;; if(number == 1){ code = R.drawable.button_tip_finder; } if(number == 2){ code = R.drawable.button_about_us; } if(number == 3){ code = R.drawable.button_power_calculator; } if(number == 4){ code = R.drawable.button_powerpedia; } if(code == id){ test.setText(""+id); } else{ test.setText(""+id); } } 

    Eu chamo isso de:

      button1.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { check(1,flipper.getCurrentView().getId()); flipper.showNext(); } }); }  button1.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { check(1,flipper.getCurrentView().getId()); flipper.showNext(); } }); 

  • o controle deslizante sempre possui lairgura padrão
  • Obtenha o status da connection VPN no Android
  • Como o novo FragmentTransaction commitNow () está funcionando internamente?
  • Android MVP open Atividade do Presenter, anti-padrão?
  • Banco de dados Android corrompido, mas pode ser aberto no SQLite Manager. Recuperável?
  • Entrada de voz paira preencher text em android?
  • 2 Solutions collect form web for “Obter ID de recurso do ImageView”

    Faça isso deste modo:

     private void setFlipperImage(int res) { image = new ImageView(getApplicationContext()); image.setBackgroundResource(res); image.setTag(res); //<------ flipper.addView(image); } 

    e depois:

     button1.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { check(1,(Integer)flipper.getCurrentView().getTag());//<---- flipper.showNext(); } }); } button1.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { check(1,(Integer)flipper.getCurrentView().getTag());//<---- flipper.showNext(); } }); 

    BTW use else em todo o seu código, por favor, por exemplo:

      if(number == 1){ pic = R.drawable.pic1; } else if(number == 2){ pic = R.drawable.pic2; } else if(number == 3){ pic = R.drawable.pic3; } 

    que este possa ajudá-lo,

     int icon = getResources().getIdentifier([YOUR IMAGE NAME], "drawable", getPackageName()); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.