开发者

Android image button problem

imgvw_back.se开发者_JAVA百科tOnClickListener(this);
imgvw.setOnClickListener(this);
static id=10

@Override
public void onClick(View v) {
   // TODO Auto-generated method stub
   switch(v.getId())
   {
     case R.id.back:
      Log.v("back",""+id--);
      break;

     case R.id.forward:
       Log.v("next",""+id++);
       break;                          
    }
}

i am using this kind of concept but mostly fire R.id.back part ,what can i do plz give solution for this problem...


The id may not be what you think it is, you could do something like this.

imgvw_back.setOnClickListener(this);
imgvw.setOnClickListener(this);
static id=10

@Override
public void onClick(View v)
{
   if(v == imgvw_back)
   {
      Log.v("back",""+id--);
   }
   else if(v == imgvw)
   {
       Log.v("next",""+id++);         
   }
}


Use inline onClickListeners for each button.


imgvw_back.setOnClickListener(new onClickListener(){

@Override
public void onClick(View v){
Log.v("back", "")
}
});


Is imgvw your forward button? Just wondering, cause your back button is imgvw_back, would assume forward would be named accordingly imgvw_forward.

You're probably missing missing to set the clickListener to the forward button as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜