Note that there are some explanatory texts on larger screens.

plurals
  1. POButton not clicking in Portrait Mode
    text
    copied!<p>I have a button to which I attach an onClickListener via code. I have to to this through code because it's in a fragment.</p> <p>The listener works fine when in landscape mode, but when it's in portrait it doesn't. There's no "click" sound even.</p> <p>In my xml file, I set the initial visibility of the button to invisible and then make it visible later when the user clicks a radio button in the same Viewgroup as the button. The onclicklisteners of the radiobuttons are working just fine in both portrait and landscape mode.</p> <p>Now if I remove the "android:visibility="invisible" code in xml, the onclickstener works fine in portrait mode! But of course I need it invisible till the user clicks a radiobutton otherwise the UI doesn't make sense. Very weird indeed.</p> <p>Here's my code:</p> <pre><code>private void setOnClickForSaveButton(View v) { Button changeFundsSave = (Button) v.findViewById(R.id.change_funds_save); changeFundsSave.setOnClickListener(saveListener); } Button.OnClickListener saveListener = new Button.OnClickListener() { @Override public void onClick(View v) { //Get the rootview View rootView = v.getRootView(); EditText changeFundsEdit = (EditText) rootView.findViewById(R.id.change_funds_edit); if(changeFundsEdit.getText().toString().equals("")) { new AlertDialog.Builder(getActivity()) .setTitle( "" ) .setMessage( "Enter the number of units" ) .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }) .show(); return; } } }; private void setOnClicksForRadioButtons(View v) { RadioButton rb1 = (RadioButton)v.findViewById(R.id.add_units); RadioButton rb2 = (RadioButton)v.findViewById(R.id.remove_units); RadioButton rb3 = (RadioButton)v.findViewById(R.id.set_units); rb1.setOnClickListener(addRemoveSetButtonListener); rb2.setOnClickListener(addRemoveSetButtonListener); rb3.setOnClickListener(addRemoveSetButtonListener); } OnClickListener addRemoveSetButtonListener = new OnClickListener() { @Override public void onClick(View v) { // Since we only have the radiobutton view, we need to get the parent View rootView = v.getRootView(); //Make the controls visible TextView changeFundsText = (TextView) rootView.findViewById(R.id.change_funds_text); EditText changeFundsEdit = (EditText) rootView.findViewById(R.id.change_funds_edit); Button changeFundsSave = (Button) rootView.findViewById(R.id.change_funds_save); changeFundsText.setVisibility(View.VISIBLE); changeFundsEdit.setVisibility(View.VISIBLE); changeFundsSave.setVisibility(View.VISIBLE); } }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload