2012-01-31 140 views
-1

我想循環通過一組ImageViews添加監聽器,我不記得如何循環並在文本中添加一個數字?Android:循環迭代

for(int i = 0; i<8; i++) 
{ 
    //convert to text and add number?      
    block(i).setOnClickListener(ActivityCheck); 
} 

感謝

+2

_convert文本並添加數_請詳細說明 – 2012-01-31 03:32:27

+0

你想說,你想把這個數字印到你的ImageView中? – OleGG 2012-01-31 03:41:57

回答

0

您可以通過控制以這種方式LinearLayout(擴展ViewGroup和其他佈局)迭代:

final LinearLayout yourLayout = (LinearLayout) findViewById(R.layout.yourLayout); 

for (int i = 0; i < yourLayout.getChildCount(); i++) { 
    Object block = yourLayout.getChildAt(i); 
} 
0

如果我理解正確。

for(int i = 0; i<8; i++) 
{ 
    //sets the text of block to the string value of the position (1-8) 
    block(i).setText(Integer.parseToString(i)); 
    block(i).setOnClickListener(ActivityCheck); 
} 

原諒我,如果我不明白你想達到什麼目的。