Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add imagebuttons to gridview in android
    text
    copied!<p>I can not figure out how to add imagebuttons to my gridview. I have to have individual code to execute for each imagebutton, because they do completely different things. How can I do it? </p> <p>I ended up using a tablelayout instead</p> <p>Code:</p> <pre><code>package com.mysoftware.mysoftwareos.launcher; import android.app.Activity; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; public class MainActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Import views //Setup onClickListener for the buttons //Setup GridView } @Override public boolean onKeyDown(int KeyCode, KeyEvent event) { if ((KeyCode == KeyEvent.KEYCODE_BACK)) { //Do nothing to prevent the back button to kill the launcher return true; } return super.onKeyDown(KeyCode, event); } public void onClick(View src) { switch(src.getId()) { } } } </code></pre> <p>Xml:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FF8090A0" &gt; &lt;GridView android:id="@+id/appsGridView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:numColumns="3" &gt; &lt;/GridView&gt; &lt;/RelativeLayout&gt; </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