Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't use buttons. Use a ListView in your activity which uses a LinearLayout for each line; the LinearLayout (which is set to horizontal) in turn contains the image and the text. To fill up the list, you use a custom ListAdapter as PravinCG has said. Use an OnItemClickListener to act.</p> <p>I.e.: The main layout:</p> <pre><code>&lt;ListView android:id="@+id/android:list" android:layout_height="wrap_content" android:layout_width="match_parent"&gt;&lt;/ListView&gt; </code></pre> <p>The row_layout:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;ImageView android:layout_width="wrap_content" android:id="@+id/imageView1" android:src="@drawable/addevent" android:layout_height="wrap_content" android:layout_gravity="right"&gt;&lt;/ImageView&gt; &lt;TextView android:id="@+id/textView1" android:text="TextView" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_height="wrap_content" android:layout_gravity="center_vertical"&gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre> <p>Create a new adapter in your activity (extends ListActivity) - this code assumes you have an instance of a class "YourButtonClass" for each "button" (=row):</p> <pre><code>class ButtonRowAdapter extends BaseAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { View v= convertView; if (v == null) { LayoutInflater vi= (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); v= vi.inflate(R.layout.row_layout, null); } YourButtonClass c= getItem(position); ((ImageView) v.findViewById(R.id.imageView1)).setImageResource(c.getImage()); ((TextView) v.findViewById(R.id.textView1)).setText(c.getText()); return v; } @Override public int getCount() { return &lt;"button" count&gt;; } @Override public Object getItem(int position) { return &lt;"button" at position position&gt;; } @Override public long getItemId(int position) { return 0; } } </code></pre> <p>Finally, instantiate it in onCreate() and add a listener.</p> <pre><code>fButtonRowAdapter= new ButtonRowAdapter(this); setListAdapter(fButtonRowAdapter); getListView().setOnItemClickListener(...); </code></pre> <p>There you go.</p>
    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. 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