示例#1
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   final ViewHolder holder =
       ViewHolder.get(MainActivity.this, convertView, R.layout.book_list_item, position, parent);
   Book item = App.courseList.get(position);
   holder
       .setText(R.id.book_name, item.book_name)
       .setText(R.id.book_course, "相关课程:" + item.course_name)
       .setText(R.id.book_price, "¥" + item.book_price)
       .setText(R.id.book_publish, "出版社:" + item.pub_house)
       .setText(R.id.book_order, item.ordered == null ? "未预定" : "已预定")
       .setColor(R.id.left_color, Color.parseColor(colors[(int) (Math.random() * 4)]))
       .setBackgroundResource(
           R.id.book_order, item.ordered == null ? R.mipmap.not_order : R.mipmap.is_order);
   holder
       .getConvertView()
       .setOnTouchListener(
           new View.OnTouchListener() {
             @Override
             public boolean onTouch(View v, MotionEvent event) {
               switch (event.getAction()) {
                 case MotionEvent.ACTION_DOWN:
                   holder
                       .getView(R.id.content)
                       .setBackgroundResource(R.drawable.list_item_selected_bg);
                   return true;
                 case MotionEvent.ACTION_MOVE:
                   return true;
                 case MotionEvent.ACTION_CANCEL:
                   holder
                       .getView(R.id.content)
                       .setBackgroundResource(R.drawable.list_item_normal_bg);
                   return true;
                 case MotionEvent.ACTION_UP:
                   holder
                       .getView(R.id.content)
                       .setBackgroundResource(R.drawable.list_item_normal_bg);
                   if (list_clickable) {
                     buy(
                         App.courseList.get(listView.getPositionForView(v)),
                         listView.getPositionForView(v));
                   }
                   return true;
               }
               return false;
             }
           });
   return holder.getConvertView();
 }