以下是我的代码。此代码正常工作,但如果显示国家/地区正确,我想获取数组中显示图像的值进行测试。请帮我 。我陷入了这种活动。感谢您的帮助。
public class MainActivity extends Activity implements OnClickListener {
private boolean blocked = false;
private Handler handler = new Handler();
ViewFlipper flippy;
Button show;
TextView view;
int flags[] = { R.drawable.afghan, R.drawable.albania, R.drawable.algeria };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.flipper);
flippy = (ViewFlipper) findViewById(R.id.viewFlipper1);
show = (Button) findViewById(R.id.button1);
view = (TextView) findViewById(R.id.textView1);
for (int i = 0; i < flags.length; i++) {
setflipperimage(flags[i]);
}
}
private void setflipperimage(int i) {
// TODO Auto-generated method stub
Log.i("Set Filpper Called", i + "");
ImageView image = new ImageView(getApplicationContext());
image.setBackgroundResource(i);
flippy.addView(image);
}
答案 0 :(得分:2)
这将用于获取当前的子ID
viewFlipper.getDisplayedChild();
答案 1 :(得分:2)
不要在循环中调用它,在点击或触摸时使用它:
i+=1;
flippy.setDisplayedChild(flags[0]);