setOnItemClickListener() not working on custom ListView @ Android

Viewed 34092

I have Implemented a custom ListView by extending LinearLayout for every row. Every row has a small thumbnail, a text and a check box. The list view is deployed properly and I can scroll and fling through it without any problems.

But The ListView doesn't seem to respond to the setOnItemClickListener() at all, So I had to find a workaround by setting click listener in the getView() of the Text inside every row which is obviously creating problem when I am trying to reuse the adapter. Does anyone have a solution?

6 Answers

Did you made any ViewHolder in your extended adapter class? If yes, then make an instance of your that placeholder in the setOnItemClickListener() something will may work like this.

@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {        
        View rowView = v;
        if (rowView == null) {
            LayoutInflater inflater = this.getLayoutInflater();
                // GET INFLATE OF YOUR LAYOUT.
            rowView = inflater.inflate(R.layout.projectpeopledescrate, null);
             // CUSTOM ViewHolder Class Created in Adapter.
// name,title,comment are my components on the same listview clicked item.
            PPDViewHolder viewHolder = new PPDViewHolder();
            viewHolder.name     = (TextView) rowView.findViewById(R.id.ppeopledescrvname);
            viewHolder.title    = (TextView) rowView.findViewById(R.id.ppeopledescrvtime);
            viewHolder.comment  = (TextView) rowView.findViewById(R.id.ppeoplervcomment);
            viewHolder.hiddenLayout = (RelativeLayout) rowView.findViewById(R.id.hiddenCommentPanel); 
            rowView.setTag(viewHolder);
        }
          // ANOTHER object instance to apply new changes.
        PPDViewHolder holder = (PPDViewHolder) rowView.getTag();
// I've setted up visibility over the components. You can set your onClickListener over your buttons.
        holder.comment.setVisibility(View.GONE);
        holder.name.setVisibility(View.GONE);
        holder.title.setVisibility(View.GONE);
        holder.hiddenLayout.setVisibility(View.VISIBLE);
        holder.hiddenLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT));
        holder.hiddenLayout.bringToFront();

    }

Hope, you want something same. Good Luck!

Related