0

我正在使用下面的代码来生成动态视图列表。每个列表项都有一个名为“btn_drag”的按钮。on Touch of this button 我想拖动视图项目并希望根据拖动对项目进行排序。但我无法找到如何做到这一点。请帮我。我的代码是:

    public void dynamicView() {

    final List<ImageView> delete= new LinkedList<ImageView>();
     LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        for ( i = 0; i < templates.length; i++) {
            final View customView = linflater.inflate(R.layout.order_template_item,
                    null);
            btn_red=(ImageView)customView.findViewById(R.id.btn_negative);
            btn_drag=(ImageView)customView.findViewById(R.id.button_drag);
            btn_delete=(ImageView)customView.findViewById(R.id.button_delete);
           final ImageView image = (ImageView)customView.findViewById(R.id.arrow);
           final TextView text = (TextView)customView.findViewById(R.id.date);
           final TextView sku = (TextView)customView.findViewById(R.id.time);
           final TextView price = (TextView)customView.findViewById(R.id.last);
           final TextView names =(TextView)customView.findViewById(R.id.name);

           image.setId(i);
           text.setId(i);
           sku.setId(i);
           price.setId(i);
           names.setId(i);
           btn_red.setId(i);
           btn_red.setTag(i);
           btn_delete.setId(i);
           btn_drag.setId(i);
           buttons.add(btn_red);
           buttons_drag.add(btn_drag);
           delete.add(btn_delete);
          names.setText(templates[i]);

           btn_red.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(delete.get(v.getId()).getVisibility()==(View.GONE))
                {
                delete.get(v.getId()).setVisibility(View.VISIBLE);
                TranslateAnimation anim = new TranslateAnimation(100,0 , 0, 0);
                anim.setInterpolator(new BounceInterpolator());
                anim.setDuration(1000);
                delete.get(v.getId()).setAnimation(anim);
                }
                else if (delete.get(v.getId()).getVisibility()==(View.VISIBLE)) {
                    delete.get(v.getId()).setVisibility(View.GONE);
                    TranslateAnimation anim = new TranslateAnimation(0,100 , 0, 0);
                    anim.setInterpolator(new BounceInterpolator());
                    anim.setDuration(1000);
                    delete.get(v.getId()).setAnimation(anim);
                }
            }
        });
           btn_delete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            lay.removeView(customView); 

            }
        });


           lay.addView(customView);


        }

}
4

0 回答 0