title: How to set Imageview as an object?
body: <p>I am working with carousel view. With one layout, I put four images.
  And I want to set each image as an each object because I want to set a different method when each image is clicked.</p>
  
  <pre><code>    ImageButton product_photo = (ImageButton) l.findViewById(R.id.myoffer_image);
  
      product_photo.setImageResource(R.drawable.myoffers_0);
  
      product_photo.setImageResource(R.drawable.myoffers_1);
  
      product_photo.setImageResource(R.drawable.myoffers_2);
  
      product_photo.setImageResource(R.drawable.myoffers_3);
  </code></pre>
  
  <p>I tried like the code below..but surely it makes an error..</p>
  
  <pre><code>ImageButton one = product_photo.setImageResource(R.drawable.myoffers_0);
  </code></pre>
  
  <p>I don't know if my question is clear..but if you reply something to know more clear, I will explain it!</p>
  
  <p>Here is pageadapter class!</p>
  
  <pre><code>public class Myoffers_PagerAdapter extends FragmentPagerAdapter implements
      ViewPager.OnPageChangeListener {
  
  private Myoffers_LinearLayout cur = null;
  private Myoffers_LinearLayout next = null;
  private Myoffers context;
  private FragmentManager fm;
  private float scale;
  
  public Myoffers_PagerAdapter(Myoffers context, FragmentManager fm) {
      super(fm);
      this.fm = fm;
      this.context = context;
  }
  
  @Override
  public Fragment getItem(int position) 
  {
      // make the first pager bigger than others
      if (position == Myoffers.FIRST_PAGE)
          scale = Myoffers.BIG_SCALE;         
      else
          scale = Myoffers.SMALL_SCALE;
  
      position = position % Myoffers.PAGES;
      return Myoffers_Fragment.newInstance(context, position, scale);
  }
  
  @Override
  public int getCount()
  {       
      return Myoffers.PAGES * Myoffers.LOOPS;
  }
  
  //@Override
  public void onPageScrolled(int position, float positionOffset,
          int positionOffsetPixels) 
  {   
      if (positionOffset &gt;= 0f &amp;&amp; positionOffset &lt;= 1f)
      {
          cur = getRootView(position);
          next = getRootView(position +1);
  
          cur.setScaleBoth(Myoffers.BIG_SCALE 
                  - Myoffers.DIFF_SCALE * positionOffset);
          next.setScaleBoth(Myoffers.SMALL_SCALE 
                  + Myoffers.DIFF_SCALE * positionOffset);
      }
  }
  
  //@Override
  public void onPageSelected(int position) {}
  
  //@Override
  public void onPageScrollStateChanged(int state) {}
  
  private Myoffers_LinearLayout getRootView(int position)
  {
      return (Myoffers_LinearLayout) 
              fm.findFragmentByTag(this.getFragmentTag(position))
              .getView().findViewById(R.id.root);
  }
  
  private String getFragmentTag(int position)
  {
      return "android:switcher:" + context.pager.getId() + ":" + position;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Main class!</p>
  
  <pre><code>public class Myoffers extends FragmentActivity {
  public final static int PAGES = 4;
  public final static int LOOPS = 1000; 
  public final static int FIRST_PAGE = PAGES * LOOPS / 2;
  public final static float BIG_SCALE = 1.0f;
  public final static float SMALL_SCALE = 0.5f;
  public final static float DIFF_SCALE = BIG_SCALE - SMALL_SCALE;
  
  public Myoffers_PagerAdapter adapter;
  public ViewPager pager;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.myoffers);
  
      pager = (ViewPager) findViewById(R.id.myviewpager);
  
      adapter = new Myoffers_PagerAdapter(this, this.getSupportFragmentManager());
      pager.setAdapter(adapter);
      pager.setOnPageChangeListener(adapter);
  
      pager.setCurrentItem(FIRST_PAGE);
  
      pager.setOffscreenPageLimit(3);
  
      pager.setPageMargin(-100);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Fragment code
      public class Myoffers_Fragment extends Fragment {</p>
  
  <pre><code>protected static final String TAG = "Philips";
  FileOutputStream mOutputStream; 
  private String id;
  
  public static Fragment newInstance(Myoffers context, int pos, float scale)
  {
      Bundle b = new Bundle();
      b.putInt("pos", pos);
      b.putFloat("scale", scale);
  
      return Fragment.instantiate(context, Myoffers_Fragment.class.getName(), b);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      if (container == null) {
          return null;
      }
  
      LinearLayout l = (LinearLayout) inflater.inflate(R.layout.mf, container, false);
  
      int pos = this.getArguments().getInt("pos");
      TextView tv = (TextView) l.findViewById(R.id.text);
      tv.setText("Product " + pos);
  
  
      /*
       * Put images with Hard-Coding
       */
      {
      ImageButton product_photo = (ImageButton) l.findViewById(R.id.myoffer_image);
  
      product_photo.setImageResource(R.drawable.myoffers_0);
  
      product_photo.setImageResource(R.drawable.myoffers_1);
  
      product_photo.setImageResource(R.drawable.myoffers_2);
  
      product_photo.setImageResource(R.drawable.myoffers_3);
  
      }
  
  
      Myoffers_LinearLayout root = (Myoffers_LinearLayout) l.findViewById(R.id.root);
      float scale = this.getArguments().getFloat("scale");
      root.setScaleBoth(scale);
  
      return l;
      }
  </code></pre>
  
  <p>Thanks!</p>