setOnItemClickListener() not working on custom ListView @ Android

前端 未结 6 1827
刺人心
刺人心 2020-12-01 09:55

I have Implemented a custom ListView by extending LinearLayout for every row. Every row has a small thumbnail, a text and a check box.

6条回答
  •  天涯浪人
    2020-12-01 10:00

    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!

提交回复
热议问题