2

以下是我的代码。此代码有效,但如果显示国家/地区正确,我想获取数组中显示图像的值以进行测试。请帮我 。我被困在这个活动中。感谢所有帮助。

        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);
        }
4

2 回答 2

2

这将用于获取当前子 ID

   viewFlipper.getDisplayedChild();
于 2013-11-04T12:21:55.667 回答
2

不要在循环中调用它,在点击或触摸时使用它:

i+=1;
flippy.setDisplayedChild(flags[0]);
于 2013-11-04T12:34:03.077 回答