gpt4 book ai didi

java - 使用 onFling 更改 Imagebutton 图像

转载 作者:行者123 更新时间:2023-11-30 01:55:34 25 4
gpt4 key购买 nike

我只是在玩弄 Android Studio,所以我一直在硬编码手势完成时我希望看到的变化。所以我知道该按钮不会从 jabong 更改为 amazon.com(尽管提供一点帮助来实现这种动态也会有所帮助!)。

但在此之前,我遇到的麻烦是在执行 onFling 操作时更改 ImageButton 的图像。

原始图像在可绘制文件夹中,我想将其更改为的图像也是如此。

我的代码如下。

public class MainActivity extends ActionBarActivity implements GestureDetector.OnGestureListener {

private TextView expiry;
private EditText JabongImpact;
private GestureDetectorCompat gestureDetector;
private ImageButton offer_image;
private Button storebutton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

JabongImpact = (EditText) findViewById(R.id.JabongImpact);
expiry = (TextView) findViewById(R.id.expiry);
offer_image = (ImageButton) findViewById(R.id.offer_image);
this.gestureDetector = new GestureDetectorCompat(this, this);
Button mybutton = (Button) findViewById(R.id.storebutton);

mybutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://www.jabong.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
offer_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://www.jabong.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}

});

}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
JabongImpact.setText("Impact shop with Amazon today!");
expiry.setText("expires: tomorrow!");
storebutton.setText("AMAZON.IN");
return true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
this.gestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

最佳答案

你可以用这种方式改变图片

offer_image.setImageResource(R.drawable.<your drawable image>); 

关于java - 使用 onFling 更改 Imagebutton 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32305034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com