如何在ViewFlipper中执行click事件

时间:2016-05-31 12:20:07

标签: android android-viewflipper

我正在开发一个使用View-Flipper的应用程序。在这个View-Flipper中我有一个图像视图,它在自动模式下翻转图像。现在我想在视图翻转器中的每个翻转图像上执行点击监听器。所以我可以在哪里设置点击监听器事件。

java.io.FileNotFoundException: hashmap.ser (Permission denied)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
    at KMerIndex.createIndex(KMerIndex.java:121)
    at MyDriverClass.formRefIndex(MyDriverClass.java:717)
    at MyDriverClass.main(MyDriverClass.java:768)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

1 个答案:

答案 0 :(得分:1)

for (int i = 0; i < resources.length; i++) {
      ImageView imageView = new ImageView(this);
      imageView.setPadding(40, 80, 40, 80);
      imageView.setTag(i);
      imageView.setImageResource(resources[i]);

                imageView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    String id = v.getTag().toString();
                    // Toast id here
                }
            });
      mViewFlipper.addView(imageView);

     // Set in/out flipping animations
            mViewFlipper.setInAnimation(this, android.R.anim.fade_in);
            mViewFlipper.setOutAnimation(this, android.R.anim.fade_out);

        }