Arsalan Arsalan - 3 months ago 19
Android Question

How to vibrate mobile while scrolling android-wheel?

I want to vibrate mobile & play sound for each item change, when user scroll android-wheel.

I've seen this in the default time-picker of iPhone. When we scroll time in the time-picker, it plays ticking sound.

Is it possible? If yest then how ?

Kindly edit the question, If it is not asked correctly.

Answer

Try this:

import android.os.Vibrator;




ListView lv = (ListView)findViewById(R.id.list_view);
        lv.setOnScrollListener(new OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
                    // Vibrate for 500 milliseconds
                    v.vibrate(500);}
        });

Don't forget to include permission in AndroidManifest.xml file:

<uses-permission android:name="android.permission.VIBRATE"/>
Comments