2012-09-03 20 views
5

我有這樣的代碼:安卓:通過一個資源ID作爲參數

translateRight("iv1"); //iv1 is an id of an imageView 

    private void translateRight(String st){ 

    ImageView img = (ImageView)findViewById(R.id.st); 
     Animation a = AnimationUtils.loadAnimation(this, R.anim.translate_right); 
     img.startAnimation(a); 
    } 

我有「translateRight」這是顯示一個動畫的方法,但這種方法我應該通過資源ID;我嘗試了一個字符串,但它不起作用,我該怎麼辦?

+0

順便說一句 - 它更方便地通過'ImageView'本身。 –

回答

9

資源ID - 是一個整數值。只要通過一個int

private void translateRight(int resource){ 
    ImageView img = (ImageView) findViewById(resource); 
    //stuff 
} 
5

資源ID是一個整數,而不是一個字符串。