简体   繁体   English

具有自定义项布局和CheckBox的ListView-项不可单击

[英]ListView with custom item layout and CheckBox - item is not clickable

I have a ListView with custom Layout for Item: 我有一个带有自定义布局的ListView:

(ImageView, TextView, 2xImageView andd CheckBox). (ImageView,TextView,2xImageView和d 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. 我希望我的项目易于理解(可以调用OnItemClickListener),可以选择(以便我可以选择一个项目),并且可以切换CheckBox并更改其状态。

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. 您可能必须在适配器的getView()方法中为评级栏创建自己的侦听器。

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 您可以在这里看到类似这样的完整示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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