I am creating a android application. Here I have a imageview . my goal is to get next picture from database when move the finger on image
float nPicturePositionM = 0;
public boolean onTouch(View v, MotionEvent event) {
boolean aHandledL = false;
if (event.getAction() == MotionEvent.ACTION_MOVE) {
float nNewPicturePosL = event.getX();
if (nPicturePositionM < nNewPicturePosL) {
nPicturePositionM = nNewPicturePosL;
GetPictures(true);
} else {
nPicturePositionM = nNewPicturePosL;
GetPictures(false);
}
aHandledL = true;
}
return aHandledL;
//return false;
}
How can i handle it using touch event? Image should slide as in we do it in gallery
Firstly you declare an imageview in your xml :
<ImageView
android:id="@+id/imageview1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="45dp"
android:layout_centerHorizontal="true" />
Then in your activity you initialize the component :
private ImageView image1;
In onCreate :
this.image1= (ImageView)this.findViewById(R.id.imageview1);
this.image1.setImageResource(R.drawable.NAMEOFIMAGE);
The next step is detecting if the image is "clicked". You can then use an online database or an SQLite database to save the images or the path to the images, the database part of it is a large part to teach from scratch depending which route you want to go with:
this.image1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view == findViewById(R.id.imageview1)) {
//PUT IN CODE HERE TO GET NEXT IMAGE
}
}
});
I hope this helps. Let me know how it goes :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With