Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom ListView not being selected on click
    text
    copied!<p>So I have looked through a lot of other answers but have not been able to get my app to work how I want it. I basically want the list view that has the text and <code>check mark</code> to the <code>right</code>, but then an addition button to the left. Right now my list view shows up but the check image is never changed.</p> <p>Edit: after a helpful comment I discovered that the rows can be selected by using the arrow (up/down) on the emulator, this highlights the row how I want. However, when I click the row it does not become selected like I want it to. Also, if it helps the list view is being used inside a dialog box.</p> <p>Selector:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_selected="true" android:drawable="@drawable/accept_on" /&gt; &lt;item android:drawable="@drawable/accept" /&gt; &lt;/selector&gt; </code></pre> <p>Row 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:id="@+id/layout" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:background="#EEE"&gt; &lt;ImageButton android:id="@+id/goToMapButton" android:src="@drawable/go_to_map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" /&gt; &lt;TextView android:id="@+id/itemName" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:textColor="#000000" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:layout_weight="1" /&gt; &lt;Button android:id="@+id/checkButton" android:background="@drawable/item_selector" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>MapAdapter:</p> <pre><code>import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; public class MapAdapter extends ArrayAdapter&lt;String&gt;{ Context context; int layoutResourceId; String data[] = null; LayoutInflater inflater; LinearLayout layout; public MapAdapter(Context context, int layoutResourceId, String[] data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; inflater = LayoutInflater.from(context); } @Override public String getItem(int position) { return data[position]; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = new ViewHolder(); if(convertView == null) { convertView = inflater.inflate(R.layout.map_item_row, null); layout = (LinearLayout)convertView.findViewById(R.id.layout); holder.map = (ImageButton)convertView.findViewById(R.id.goToMapButton); holder.name = (TextView)convertView.findViewById(R.id.itemName); //holder.check = (Button)convertView.findViewById(R.id.checkButton); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } layout.setBackgroundColor(0x00000004); holder.name.setText(getItem(position)); return convertView; } static class ViewHolder { ImageButton map; TextView name; Button check; } } </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