Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would change the onclick in your xml to android:onClick="onClick" for both buttons and call your methods there in once place. Just for looks. Make sure your class implements OnClickListener.</p> <p>Then your onClick method would be :</p> <pre><code>@Override public void onClick(View v) { Intent iExp = null; switch (v.getId()) { case R.id.imageButton1: iExp = new Intent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://agent.electricimp.com/BGSBpog28J0u?led=1")); break; case R.id.imageButton2: iExp = new Intent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://agent.electricimp.com/BGSBpog28J0u?led=0")); break; } startActivity(iExp); } </code></pre> <p>PS onClick on imagebuttons not available till 1.6 and your onClick in the xml has a . when it should be a :</p> <p>Make sure your manifest has:</p> <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt; </code></pre> <p>Your xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ImageButton android:id="@+id/imageButton1" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:clickable="true" android:src="@drawable/ic_launcheronswitch" /&gt; &lt;ImageButton android:id="@+id/imageButton2" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="onClick" android:clickable="true" android:src="@drawable/ic_launcheroffswitch" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Your class:</p> <pre><code>package com.modsbyus.onoff; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; public class MainActivity extends Activity implements OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void onClick(View v) { Intent iExp = null; switch (v.getId()) { case R.id.imageButton1: iExp = new Intent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://agent.electricimp.com/BGSBpog28J0u?led=1")); break; case R.id.imageButton2: iExp = new Intent(new Intent(Intent.ACTION_VIEW, Uri.parse("https://agent.electricimp.com/BGSBpog28J0u?led=0")); break; } startActivity(iExp); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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