Note that there are some explanatory texts on larger screens.

plurals
  1. POListView onItemClick is not responding to clicks
    text
    copied!<p>I have ListView in my main Activity(extends Activity) and I am trying to implement a onItemClick for the items in the listview. When the user clicks the listview entry a dialog will be shown asking for user input. With the below code I am not getting any response from the app when the listview items are clicked. Any thoughts on why this is happening? Thanks!</p> <pre><code> list1 = (ListView) findViewById(R.id.lstPhotos); m_adapter = new PhotoAdapter(this, R.layout.listview_row, m_photos); list1.setAdapter(m_adapter); list1.setClickable(true); list1.setItemsCanFocus(false); list1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { Log.v("listview", "listview item clicked"); appErrorAlert("test", "test"); } }); </code></pre> <p>listview_row.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:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip"&gt; &lt;ImageView android:id="@+id/txtPhotoLocationActual" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:focusable="false" android:focusableInTouchMode="false" /&gt; &lt;TextView android:id="@+id/txtPhotoCaptionActual" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip" android:textColor="#FFFFFF" android:layout_alignParentRight="true" android:layout_toRightOf="@id/txtPhotoLocationActual" android:gravity="center_vertical" android:focusable="false" android:focusableInTouchMode="false" /&gt; &lt;TextView android:id="@+id/txtLocation" android:layout_width="0dip" android:layout_height="0dip" android:padding="3dip" android:textColor="#FFFFFF" android:layout_alignParentRight="true" android:gravity="center_vertical" android:focusable="false" android:focusableInTouchMode="false" /&gt; &lt;ImageButton android:id="@+id/delete" android:layout_width="70dip" android:layout_height="70dip" android:src="@drawable/delete_button" android:background="@null" android:layout_alignParentRight="true" android:gravity="center_vertical" android:focusable="false" android:focusableInTouchMode="false" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>custom adapter where delete button click is called</p> <pre><code>public class PhotoAdapter extends ArrayAdapter&lt;Photo&gt; { private final ArrayList&lt;Photo&gt; objects; public PhotoAdapter(Context context, int textViewResourceId, ArrayList&lt;Photo&gt; objects) { super(context, textViewResourceId, objects); this.objects = objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { final Photo i = objects.get(position); View v = convertView; if (v == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.listview_row, null); v.setClickable(true); v.setFocusable(true); } if (i != null) { ImageView thumb = (ImageView) v .findViewById(R.id.txtPhotoLocationActual); TextView mtd = (TextView) v .findViewById(R.id.txtPhotoCaptionActual); TextView loc = (TextView) v.findViewById(R.id.txtLocation); ImageButton delete = (ImageButton) v.findViewById(R.id.delete); delete.setTag(position); if (thumb != null) { String imagePath = i.getLocation(); loc.setText(imagePath); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bm = BitmapFactory.decodeFile(imagePath, options); final int REQUIRED_SIZE = 70; int scale = 1; while (options.outWidth / scale / 2 &gt;= REQUIRED_SIZE &amp;&amp; options.outHeight / scale / 2 &gt;= REQUIRED_SIZE) scale *= 2; BitmapFactory.Options options2 = new BitmapFactory.Options(); options2.inSampleSize = scale; Bitmap bm2 = BitmapFactory.decodeFile(imagePath, options2); thumb.setImageBitmap(bm2); delete.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { Log.e("delete", "delete pressed"); objects.remove(i); notifyDataSetChanged(); } }); } if (mtd != null) { mtd.setText(i.getCaption()); } } return v; } } </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