Open
Conversation
equiptice
commented
Jul 23, 2025
| @@ -0,0 +1,2 @@ | |||
| app/src/main/java/com/example/swipematch/ | |||
| app/src/main/res/layout/ No newline at end of file | |||
Owner
Author
There was a problem hiding this comment.
package com.example.swipematch;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private int currentIndex = 0;
private String[] names = {"Alex", "Sam", "Jamie", "Taylor", "Jordan"};
private int[] images = {
R.mipmap.ic_launcher,
R.mipmap.ic_launcher,
R.mipmap.ic_launcher,
R.mipmap.ic_launcher,
R.mipmap.ic_launcher
};
private float xDown;
private ImageView cardImage;
private TextView cardText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cardImage = findViewById(R.id.cardImage);
cardText = findViewById(R.id.cardText);
updateCard();
cardImage.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
xDown = event.getX();
return true;
case MotionEvent.ACTION_UP:
float xUp = event.getX();
if (xUp - xDown > 150) {
nextCard("Liked");
} else if (xDown - xUp > 150) {
nextCard("Disliked");
}
return true;
}
return false;
}
});
}
private void updateCard() {
if (currentIndex < names.length) {
cardImage.setImageResource(images[currentIndex]);
cardText.setText(names[currentIndex]);
} else {
cardText.setText("No more cards!");
cardImage.setVisibility(View.INVISIBLE);
}
}
private void nextCard(String action) {
cardText.setText(action + ": " + names[currentIndex]);
cardImage.postDelayed(new Runnable() {
@Override
public void run() {
currentIndex++;
cardImage.setVisibility(View.VISIBLE);
updateCard();
}
}, 500);
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.