I need to take an image from an int Array and show then in Imageview when i swipe from bottom to top and top to bottom.
The GestureDetector works well but i want to take an image from an int [] and put then in Imageview when swipe.
Exemple :
int [] imageBank = new int[] {
R.drawable.image0,
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4, };
Swipe top to bottom, take image 0 from [ ], show in Imageview
Swipe top to bottom, take image 1 from [ ], show in Imageview
Swipe bottom to top, take image 0 from [ ], show in Imageview
Swipe bottom to top, take image 4 from [ ], show in Imageview
Complete MainActivity
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import driss.moodtracker.R;
import driss.moodtracker.component.SwipeGestureDetector;
public class MainActivity extends AppCompatActivity {
private SwipeGestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gestureDetector = new SwipeGestureDetector(this);
Button button_comment = (Button) findViewById(R.id.button1);
Button button_calendar = (Button) findViewById(R.id.button2);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
public void onSwipe(SwipeGestureDetector.SwipeDirection direction) {
ImageView imagePic = (ImageView) findViewById(R.id.imageview);
ConstraintLayout currentLayout = (ConstraintLayout) findViewById(R.id.main_layout);
// ARRAY OF SMILEYS LIST
int [] arraySmileys = new int[] {
R.drawable.smiley_super_happy,
R.drawable.smiley_happy,
R.drawable.smiley_normal,
R.drawable.smiley_disappointed,
R.drawable.smiley_sad,
};
// HOW CAN I DO ?
String message = "";
switch (direction) {
case LEFT_TO_RIGHT:
message = "Left to right swipe";
break;
case RIGHT_TO_LEFT:
message = "Right to left swipe";
break;
case TOP_TO_BOTTOM:
imagePic.setImageResource(R.drawable.smiley_disappointed);
currentLayout.setBackgroundResource(R.color.faded_red);
message = "Top to bottom swipe";
break;
case BOTTOM_TO_TOP:
currentLayout.setBackgroundResource(R.color.light_sage);
imagePic.setImageResource(R.drawable.smiley_super_happy);
message = " Bottom to top swipe";
break;
}
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}
Thanks you for your help
A new student.