Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - ImageButton onClick working in ICS and JB but not in GB
    text
    copied!<p>I've created a somewhat simple layout with a total of 4 buttons: 3 buttons at the bottom of the layout are side by side (in a RelativeLayout) and on huge button almost in the middle of the screen.</p> <p>On Ice Cream Sandwich and Jellybean, I can click any of the buttons and everything works fine (i.e.The respective onClick functions are called) but weirdly enough on Gingerbread any of the 3 buttons at the bottom work but not the one in the middle. onClick fires off many instructions, none of which are being executed so as far as I can tell, it's not being called and I don't know why.</p> <p>Code for layout is given below. Any help is greatly appreciated!</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/main_off" android:orientation="vertical" android:weightSum="10" &gt; &lt;ImageButton android:id="@+id/button_activate" android:layout_width="155dp" android:layout_height="0dp" android:layout_gravity="center_horizontal" android:layout_marginTop="170dp" android:layout_weight="7.2" android:background="@drawable/transparent" android:clickable="true" android:contentDescription="@string/app_name" android:onClick="activate" android:src="@drawable/transparent" /&gt; &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="30dp" android:layout_marginTop="80dp" android:layout_weight="2" &gt; &lt;ImageButton android:id="@+id/button_help" android:layout_width="90dp" android:layout_height="fill_parent" android:layout_centerHorizontal="true" android:layout_marginTop="0dp" android:background="@drawable/transparent" android:clickable="true" android:contentDescription="@string/app_name" android:onClick="openhelp" android:src="@drawable/transparent" /&gt; &lt;ImageButton android:id="@+id/button_settings" android:layout_width="55dp" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_marginTop="0dp" android:layout_toLeftOf="@+id/button_help" android:background="@drawable/transparent" android:clickable="true" android:contentDescription="@string/app_name" android:onClick="opensettings" android:src="@drawable/transparent" /&gt; &lt;ImageButton android:id="@+id/button_contact" android:layout_width="70dp" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:layout_marginTop="0dp" android:layout_toRightOf="@+id/button_help" android:background="@drawable/transparent" android:clickable="true" android:contentDescription="@string/app_name" android:onClick="opencontact" android:src="@drawable/transparent" /&gt; &lt;/RelativeLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Activity that calls the layout (main.xml):</p> <pre><code>//bunch of imports public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout layout = (LinearLayout) findViewById (R.id.main_layout); boolean serviceOn = isMyServiceRunning(); if(serviceOn==true) layout.setBackgroundResource(R.drawable.main_on); else if (serviceOn==false) layout.setBackgroundResource(R.drawable.main_off); } @Override protected void onResume() { super.onResume(); LinearLayout layout = (LinearLayout) findViewById (R.id.main_layout); boolean serviceIsOn = isMyServiceRunning(); if(serviceIsOn==true) layout.setBackgroundResource(R.drawable.main_on); else if (serviceIsOn==false) layout.setBackgroundResource(R.drawable.main_off); } public void activate(View v){ LinearLayout layout = (LinearLayout) findViewById (R.id.main_layout); Resources res = getResources(); Drawable on = res.getDrawable(R.drawable.main_on); Drawable off = res.getDrawable(R.drawable.main_off); if (layout.getBackground().getConstantState() == off.getConstantState()){ layout.setBackgroundResource(R.drawable.main_on); Toast.makeText(getApplicationContext(), "App has been activated", Toast.LENGTH_SHORT).show(); turnon(); } else if (layout.getBackground().getConstantState() == on.getConstantState()){ layout.setBackgroundResource(R.drawable.main_off); Toast.makeText(getApplicationContext(), "App has been deactivated", Toast.LENGTH_SHORT).show(); turnoff(); } } } </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