Search code examples
androidbuttononclickvisibilityinvisible

Android - Can't Click on Button


I have a button that is declared "gone" in the XML file:

android:visibility="gone" 

Therefore, by default the button is hidden. The button will become visible depending on another condition in the .java by the following line.:

smsexplain.setVisibility(0);

I have set up a proper onClickListener for the button via:

Button edit = (Button) findViewById(R.id.edithookup_req);
        edit.setVisibility(0);
        edit.setOnClickListener(onEdit);

The problem arises in runtime. The button shows up like it is suppose to; however, the button cannot be touched. The only way to set off the onClickListener is to use the D-pad or scroll-ball on the physical phone.

Any ideas?


Solution

  • You shouldn't use setVisibility() with a 0.

    Try using the correct variable from the View class. For example: View.VISIBLE.