Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there anything equivalent to setImageResource for buttons?
    primarykey
    data
    text
    <p>I am creating a custom adapter so that I can put a button in a listView. I was putting it in just like I would an image and then I got to this line of code in the tutorial:</p> <pre><code>button.setImageResource(current_item.getButton_id()); </code></pre> <p>I tried changing it to <code>setButtonResource</code>, but there is no method for that. Thanks for any help. I want it to look like this where there is a listview with a textview and a button. I got the text put in just fine, but I can't figure out how to get a button in ther listview.</p> <p><img src="https://i.stack.imgur.com/bOjQ8.png" alt="enter image description here"></p> <p>This is my adapter:</p> <pre><code>private class MyListAdapter extends ArrayAdapter&lt;SchoolsListClass&gt;{ public MyListAdapter() { super(searchResults.this, R.layout.da_item, mySchools); } @Override public View getView(int position, View convertView, ViewGroup parent) { //Make sure we have a view to work with (may have been given null View itemView = convertView; if (itemView == null){ itemView = getLayoutInflater().inflate(R.layout.da_item, parent, false); } //Find school to work with SchoolsListClass currentSchoolsListClass = mySchools.get(position); //Fill the view //school name TextView schoolText = (TextView) itemView.findViewById(R.id.item_schoolName); schoolText.setText(currentSchoolsListClass.getSchool_name()); //subscribe/unsubscribe button Button button = (Button)itemView.findViewById(R.id.item_subscribeButton); button..setImageResource(currentSchoolsListClass.getButton_id());//This is the line of code I am having trouble with. I want it to do exactly what it is doing for images, but use buttons instead of images. return itemView; } </code></pre> <p>SchoolsListClass:</p> <pre><code>package com.parse.starter; public class SchoolsListClass { private String school_name; private int button_id; public SchoolsListClass(String school, int button){ super(); this.school_name = school; this.button_id = button; } public String getSchool_name() { return school_name; } public int getButton_id() { return button_id; } } </code></pre> <p>school_results.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listMain" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="18dp" android:text="Title" android:textAppearance="?android:attr/textAppearanceLarge" /&gt; &lt;ListView android:id="@+id/schoolListView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" &gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>da_item.xml:(sample for items in my listview)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/itemLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_marginLeft="4dp" &gt; &lt;TextView android:id="@+id/item_schoolName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/item_subscribeButton" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_toLeftOf="@+id/item_subscribeButton" android:ellipsize="end" android:text="Central Wisconsin Christian School" android:textSize="@dimen/school_name_size" /&gt; &lt;Button android:id="@+id/item_subscribeButton" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Button" /&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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