当列表滚动到结尾时,禁用列表视图上的滚动

时间:2014-04-21 08:02:30

标签: android listview

我希望在列表滚动到已经结束时禁用向上滚动,或者由于列表视图中的某些问题,当listscrolls到顶部时禁用向下滚动。问题是当我尝试更多滚动时(当列表已经滚动到结束时)它将再次显示倒数第二个条目并再次显示滚动。

这是我的适配器:

public class ActivateDetailTicketFooterAdapter extends ArrayAdapter<VisitorEntity>
{
    Context context;
    int id;
    LayoutInflater inflater;
    List<VisitorEntity> list;
    View v;
    VisitorEntity entity;
    ImageLoader imageLoader;
    String status;

    public ActivateDetailTicketFooterAdapter(Context context, int textViewResourceId,
            List<VisitorEntity> objects, String status) { 
        super(context, textViewResourceId, objects);
        this.context = context;
        id = textViewResourceId;
        this.list = objects;
        imageLoader=new ImageLoader(context);
        this.status = status;
        inflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    private static class ViewHolder{
        TextView age, gender, passNo, edit;
        ImageView image;
        LinearLayout parentRowLl, passdeactivatedLl,parent;
    }

    public void setViewHolder(ViewHolder holder){
        holder.parent=(LinearLayout)v.findViewById(R.id.parent);
        holder.age = (TextView) v.findViewById(R.id.age);
        holder.gender = (TextView)v.findViewById(R.id.gender);
        holder.passNo = (TextView) v.findViewById(R.id.pass_no);
        holder.edit = (TextView) v.findViewById(R.id.edit);     
        holder.image = (ImageView) v.findViewById(R.id.image);
        holder.parentRowLl = (LinearLayout) v.findViewById(R.id.parent_row);
        holder.passdeactivatedLl = (LinearLayout) v.findViewById(R.id.pass_deactivated);


    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


        v = convertView;
        entity = list.get(position);
        ViewHolder holder = null;
        if (v == null){



            v = inflater.inflate(id, null);
            holder = new ViewHolder();
            setViewHolder(holder); 
        }  
        else{
            holder = (ViewHolder) v.getTag();
        }

        /*v.setTag(holder);
        }else{
            holder = (ViewHolder) v.getTag();
        }*/
        if (holder!=null) {


        String pass_no = entity.getPassNo();
        pass_no = pass_no.substring(pass_no.lastIndexOf("/")+1, pass_no.length());
        holder.age.setText("Age: "+entity.getAge());
        holder.gender.setText("Gender: "+entity.getGender());
        holder.passNo.setText("Pass no: "+pass_no);
        //String name = entity.getImage().trim();
        //name = name.substring(name.lastIndexOf("/")+1, name.length());
        if (entity.getImage().contains("no_upload")) {
            holder.image.setImageResource(R.drawable.demo_normal);  
            entity.setIsDemo("yes");
        }
        else {
            imageLoader.displayListingImage(entity.getImage(), holder.image, "0");
            entity.setIsDemo("no");
        }



        if(status.equalsIgnoreCase("completed")){
            holder.edit.setVisibility(View.INVISIBLE);
        }else{
            holder.edit.setVisibility(View.VISIBLE);
        }

        holder.image.setTag(entity.getImage());
        if(entity.getIsPassDeactivated().equals("1")){
            holder.passdeactivatedLl.setVisibility(View.VISIBLE);
        }else{
            holder.passdeactivatedLl.setVisibility(View.INVISIBLE);
        }
        holder.edit.setTag(position);
        holder.parentRowLl.setTag(position);
        holder.parentRowLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!status.equalsIgnoreCase("completed")){
                    int pos = (Integer) v.getTag();
                    Intent intent = new Intent(context, EditCustomerDetail.class);
                    intent.putExtra("age", list.get(pos).getAge());
                    intent.putExtra("gender", list.get(pos).getGender());
                    intent.putExtra("passno", list.get(pos).getPassNo());
                    intent.putExtra("image", list.get(pos).getImage());
                    SoapConstants.imageUrl=list.get(0).getImage();
                    intent.putExtra("visitorId", list.get(pos).getVisitorId());
                    intent.putExtra("passdeactivated", list.get(pos).getIsPassDeactivated());
                    intent.putExtra("museumName", list.get(pos).getMuseumName());
                    intent.putExtra("listPosition",pos+"");


                    context.startActivity(intent);
                }
            }
        });

        holder.image.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if(list.get(position).getIsDemo().equals("no")){
                    String image = (String) v.getTag();
                    if (image.contains("http://")) {
                        image = image.substring(image.lastIndexOf("/")+1, image.length());
                    }

                    showImage(image);
                }
            }
        });
        /*android.view.ViewGroup.LayoutParams lp=holder.parent.getLayoutParams();
        SoapConstants.visistorListHeight=lp.height;*/
        }
        return v;
    }

    public void showImage(String image){
        final Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
        dialog.setContentView(R.layout.image_dialog);
        ImageView iv = (ImageView) dialog.findViewById(R.id.image);
        ((Button)dialog.findViewById(R.id.done_btn)).setOnClickListener(new View.OnClickListener() {            
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        if (image.contains(SoapConstants.imageUrlForDefault)|| image.contains(SoapConstants.imageUrlForDefault1)) {
            iv.setImageResource(R.drawable.demovsitormedium);
        }
        else {
            Bitmap bm = imageLoader.getImageFromLocal(image,true);

            if (bm!=null) {
                iv.setImageBitmap(bm);
            }
            else {
                image=image.replace("_big", "");
                Bitmap bm1 = imageLoader.getImageFromLocal(image,false);
                iv.setImageBitmap(bm1);
            }
        }
        dialog.show();
    }
}

0 个答案:

没有答案