One of the most challenging aspects of smartphone programming is the often very small amount of screen estate available, with some handsets having screen sizes of less than 3". Programming such devices would prove very frustrating if it were not for the presence of touch-screens on most of them.
Here we will create a slider button that we can drag across the screen with a finger using the view.View.OnTouchListener and view.MotionEvent classes. This will demonstrate how to make any View respond to a touch event and read the position of any movement we make.
Although there is quite a lot of code in this example, to start with all we need is a new Android project and a Button to use as a slider. Start a new project and in the res/layout/main.xml
file add the following Button:
<Button android:text="slide me" android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="6dip" />