我想在 android 4.2 上按下按钮时连续更改图片此代码仅更改一次
代码:
public void addListenerOnButton() {
b1 = (Button) findViewById(R.id.b1);
i = (ImageView) findViewById(R.id.iv);
b1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
while (event.getAction() == MotionEvent.ACTION_DOWN){
ii++;
if (ii%2==1) i.setImageResource(R.drawable.pic1); else i.setImageResource(R.drawable.pic2);
return true;
}
return false;
}
});
}