naleshmadur
naleshmadur

Reputation: 95

how to set two onclicklisteners on one imageview in android?

I am new to android development.

I have on one image in layout.I used scale animation for that image. and i am able to stop the scaling of image at particular point. now i want to resize that image on another clicklistener.

How to do that? if any idea,help.

Here is my code.

final ImageView img_graph= (ImageView)findViewById(R.id.graph01);
   final Animation AnimationScale= AnimationUtils.loadAnimation(this,R.anim.anim_scale);
   final Animation AnimationScale_reverse= AnimationUtils.loadAnimation(this,R.anim.anim_scale_reverse);


        if(flag ==FLAG_SCALE_IN) { 
            if(resp==0){
   img_graph.setOnClickListener(new ImageView.OnClickListener(){

       public void onClick(View arg0) {

        // TODO Auto-generated method stub

         img_graph.setBackgroundResource(R.drawable.page01_graph);
         img_graph.startAnimation(AnimationScale);
       }});     
            }     
            }      
        if(flag==FLAG_SCALE_OUT) { 
            if(resp==1){
   img_graph.setOnClickListener(new ImageView.OnClickListener(){

       public void onClick(View arg0) {

        // TODO Auto-generated method stub

         img_graph.setBackgroundResource(R.drawable.page01_graph);
         img_graph.startAnimation(AnimationScale_reverse);
       }});
            }
            }   

Upvotes: 0

Views: 220

Answers (2)

Paresh Mayani
Paresh Mayani

Reputation: 128438

More optimization:

public void imageViewClick(View v)
{
    if(flag==FLAG_SCALE_IN && resp==0)
        {
        }
        else if(flag==FLAG_SCALE_OUT && resp==1)
        {                     
        }
}

Upvotes: 1

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

can't we handle this case using if else in same listner ?

   img_graph.setOnClickListener(new ImageView.OnClickListener(){

       public void onClick(View arg0) {


                      if(resp==0 && flag ==FLAG_SCALE_IN) { 
                             img_graph.setBackgroundResource(R.drawable.page01_graph);
                             img_graph.startAnimation(AnimationScale);
                      }else if( resp==1 &&flag ==FLAG_SCALE_OUT) {
                           img_graph.setBackgroundResource(R.drawable.page01_graph);
                            img_graph.startAnimation(AnimationScale_reverse);
                          }
                }
       }});     

Upvotes: 3

Related Questions