2

I want to create an android app which has a seekbar that sets the distance range from the user's location kinda like Tinder does. How do I do this?

Here's what I tried so far, but I have no idea where to go from here. It's probably completely wrong tho.

Thanks for any help

public class MainActivity extends AppCompatActivity {

    public static SeekBar seek_bar;
    public static TextView text_view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        seek_bar();
    }

    public void seek_bar( ) {
        seek_bar = (SeekBar) findViewById(R.id.DistanceSeekBar);
        text_view = (TextView) findViewById(R.id.DistanceTextView);
        text_view.setText(seek_bar.getProgress() + " / " + seek_bar.getMax());

        seek_bar.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {

                    int progress_value;

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        progress_value = progress;
                        text_view.setText(progress + " / " + seek_bar.getMax());
                        Toast.makeText(MainActivity.this, "SeekBar in progress", Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                        Toast.makeText(MainActivity.this, "SeekBar in StartTracking", Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                        text_view.setText("Covered : " + progress_value + " / " + seek_bar.getMax());
                        Toast.makeText(MainActivity.this, "SeekBar in StopTracking", Toast.LENGTH_LONG).show();
                    }
                }
        );
    }
Ace
  • 2,108
  • 22
  • 29

1 Answers1

0

That is a big question, mate. We can't code the whole thing for you, but I'll throw some ideas.

Simply explained, you can associate a distance range with each level of the SeekBar.

onProgressChanged() helps you with that. Just use the "progress" parameter.

Something like:

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

    switch(progress){
        case 0:
            range = [some defined range];
        break;
        case 1:
            range = [some defined range];
        break;

        ...

    }

}

Then you just use that "range" variable with whatever Geographic system you are using. In case of Graphhopper's library, you can use:

GeoPoint a = [some geopoint];
GeoPoint b = [some other geopoint];

if (a.distance(b) <= range) {
    // do stuff
}

But you can do something similar with Google's library as well.

Let me know if this is what you wanted.

(And welcome to StackOverflow, btw)

Luís Henriques
  • 604
  • 1
  • 10
  • 30