Note that there are some explanatory texts on larger screens.

plurals
  1. POListView with custom adapter, inside a Fragment doesn't fire onItemClick event
    primarykey
    data
    text
    <p>I have a ViewProvider class for the Fragment content, which returns a ListView for one of the fragments. The ListView has a custom adapter extending the BaseAdapter class. When I try implement an item click listener, it just doesn't work. I have this code for the listener:</p> <pre><code>lv.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; a, View vi, int pos, long id) { try { Object o = lv.getItemAtPosition(pos); Event obj_itemDetails = (Event) o; Toast.makeText(context, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show(); Log.d("xxx", "output: "+obj_itemDetails.getName()); } catch(Exception e) { Log.d(Log.TAG, "Something is wrong..."); } } }); </code></pre> <p>...not even the exceptions fires. In the same ViewProvider class, I've added another list with a SimpleAdapter, and it works just fine. I initialize the list the same:</p> <pre><code>EventAdapter sta = new EventAdapter(context, events); final ListView lv = new ListView( context ); lv.setTextFilterEnabled(true); lv.setAdapter(sta); </code></pre> <p>and the other one:</p> <pre><code>final ListView v = new ListView( context ); String[] from = new String[] { "str" }; int[] to = new int[] { android.R.id.text1 }; List&lt;Map&lt;String, String&gt;&gt; items = new ArrayList&lt;Map&lt;String, String&gt;&gt;(); for ( int i = 0; i &lt; 20; i++ )...//set the items here SimpleAdapter adapter = new SimpleAdapter( context, items, android.R.layout.simple_list_item_1, from, to ); v.setAdapter( adapter ); </code></pre> <p>What am I missing, where should I look?</p> <p>Here is my EventAdapter: </p> <pre><code>public class EventAdapter extends BaseAdapter { private LayoutInflater mInflater; private List&lt;Event&gt; items = new ArrayList&lt;Event&gt;(); Context ctx; public EventAdapter(Context context, List&lt;Event&gt; items) { mInflater = LayoutInflater.from(context); this.items = items; this.ctx = context; } public int getCount() { return items.size(); } public Event getItem(int position) { return items.get(position); } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; final Event s = items.get(position); if (convertView == null) { convertView = mInflater.inflate(R.layout.list_item, null); holder = new ViewHolder(); holder.name = (TextView) convertView.findViewById(R.id.eventTitle); holder.timestamp = (TextView) convertView.findViewById(R.id.eventTime); holder.location = (TextView) convertView.findViewById(R.id.eventLocation); holder.pic = (ImageView) convertView.findViewById(R.id.eventLogo); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.name.setText(s.getName()); holder.timestamp.setText(s.getTimestamp()); holder.location.setText(s.getLocation()); if (s.getImage() != null) { holder.pic.setImageBitmap(s.getImage()); } else { // MY DEFAULT IMAGE holder.pic.setImageResource(R.drawable.ic_launcher); } return convertView; } static class ViewHolder { TextView name; TextView timestamp; TextView location; ImageView pic; } </code></pre> <p>}</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