The Carl class is self-contained and works great.
I would make an initial delay and adjust the repeat interval. For this
attrs.xml
<resources> <declare-styleable name="AutoRepeatButton"> <attr name="initial_delay" format="integer" /> <attr name="repeat_interval" format="integer" /> </declare-styleable> </resources>
AutoRepeatButton.java
public AutoRepeatButton(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AutoRepeatButton); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.AutoRepeatButton_initial_delay: initialRepeatDelay = a.getInt(attr, DEFAULT_INITIAL_DELAY); break; case R.styleable.AutoRepeatButton_repeat_interval: repeatIntervalInMilliseconds = a.getInt(attr, DEFAULT_REPEAT_INTERVAL); break; } } a.recycle(); commonConstructorCode(); }
then you can use a class like this
<com.thepath.AutoRepeatButton xmlns:repeat="http://schemas.android.com/apk/res/com.thepath" android:id="@+id/btn_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/selector_btn_delete" android:onClick="onBtnClick" android:layout_weight="1" android:layout_margin="2dp" repeat:initial_delay="1500" repeat:repeat_interval="150" />
JonA Dec 14 2018-11-11T00: 00Z
source share