2

I'm having trouble with enabling buttons while the onTouchEvent is active. In my app the user is supposed to press anywhere on the screen to see a text and while pressing the screen press a button. The problem is that while the onTouchEvent is active the buttons doesnt work. is there anyway to enable buttons while the onTouchEvent is active?

My code for the button and onToch looks like this.

 public void correctWord(){
    correct_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

                theWord.setText(((global_rules) getApplication()).NewWord(getApplicationContext()));

        }
    });
}


public boolean onTouchEvent(MotionEvent event){
    switch (event.getAction()){
        case MotionEvent.ACTION_DOWN:
            if(enableTouch) {
                holdToView.setVisibility(View.INVISIBLE);
                theWord.setVisibility(View.VISIBLE);
            }
            break;

        case MotionEvent.ACTION_MOVE:
            break;

        case MotionEvent.ACTION_UP:
            if(enableTouch) {
                holdToView.setVisibility(View.VISIBLE);
                theWord.setVisibility(View.INVISIBLE);
            }
            break;
    }
    return false;
}

edit, added the .xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_1">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rätt"
    android:id="@+id/correct_btn"
    style="@style/btn_style2"
    android:layout_alignTop="@+id/skip"
    android:layout_alignLeft="@+id/holdToView"
    android:layout_alignStart="@+id/holdToView" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text=""
    android:id="@+id/theWord"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:visibility="invisible"
    android:textStyle="bold"
    android:textSize="40dp"
    android:textColor="#ffffff" />

</RelativeLayout>
  • Could you post your *.xml too ? I think the problem is there. You should create a view that matches your screen dimmensions (which you'll be setting the onTouchListener on), and a button ON TOP of that view (which you'll be setting the onClickListener on). – DDsix Jun 18 '14 at 19:03

0 Answers0