0

Just like we can call setError() on an EditText or a TextView, I want the same to be implemented over a Button orImageView to imitate WhatsApp's record button click! It pops up: "Hold to record, release to send"

I think it is the same as EditText setError() popup. Or is there any other way to do it??

Here is what i tried : 1. Setting background to EditText or a TextView but was not clean. 2.Custom toast notification and then setting gravity .still not 100% result achieved. 3.placing an edit text with android:enabled="false" , android:inputType="none" but i m not able to achieve exact overlapping..

1 Answers1

1

I figured out a solution that worked for me from the comments..

So i have placed an edit text behind my imageview like this

            <RelativeLayout 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center" >
            <ImageView
                android:id="@+id/helpIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:src="@drawable/help" />

            <EditText
                android:id="@+id/helpMsg"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:enabled="false"
                android:hint=""
                android:inputType="none" />
            </RelativeLayout>

then on onClick event of the imageview

helpIcon.setOnClickListener(new OnClickListener() {

//use this variable only if you want to remove the toast before it automatically disappears
    private boolean isToastVisible = false;

        @Override
        public void onClick(View arg0) {
            if (!isToastVisible) {
                helpMessage.requestFocus();
                  helpMessage.setError(getResources().getString(R.string.helpText));
                isToastVisible = true;
                new CountDownTimer(5000, 1000) {

                        @Override
                        public void onTick(long millisUntilFinished) {
                        }

                        @Override
                        public void onFinish() {
                            helpMessage.setError(null);
                            isToastVisible = false;

                        }
                    }.start();
            } 
            else {
                helpMessage.setError(null);
                isToastVisible = false;
            }
        }
    });