简体   繁体   中英

ListView with custom item layout and CheckBox - item is not clickable

I have a ListView with custom Layout for Item:

(ImageView, TextView, 2xImageView andd CheckBox).

I want my item to be clikable (st that OnItemClickListener get called), selectable (so I can select an item) and also that the CheckBox can be toggled and it changes its state.

How to achieve that?

You may have to create your own listener for the rating bar like this..in your getView() method of your adapter.

public View getView(int position, View convertView,
                    ViewGroup parent) {
  View row=super.getView(position, convertView, parent);
  ViewHolder holder=(ViewHolder)row.getTag();

  if (holder==null) {   
    holder=new ViewHolder(row);
    row.setTag(holder);

    RatingBar.OnRatingBarChangeListener l=
                new RatingBar.OnRatingBarChangeListener() {
      public void onRatingChanged(RatingBar ratingBar,
                                    float rating,
                                    boolean fromTouch)  {
        Integer myPosition=(Integer)ratingBar.getTag();
        RowModel model=getModel(myPosition);

        model.rating=rating;

        LinearLayout parent=(LinearLayout)ratingBar.getParent();


      }
    };

    holder.rate.setOnRatingBarChangeListener(l);
  }

  RowModel model=getModel(position);

  holder.rate.setTag(new Integer(position));
  holder.rate.setRating(model.rating);

  return(row);
}

}

You can see a full example of something like this here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM