zoukankan      html  css  js  c++  java
  • swipelistview使用方法

    swipelistview 的xml类似这样:

    <com.fortysevendeg.swipelistview.SwipeListView
    android:id="@+id/swipe_lv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:listSelector="#ff0000"
    app:swipeActionLeft="reveal"
    app:swipeActionRight="reveal"
    app:swipeAnimationTime="0"
    app:swipeBackView="@+id/back"                 //这个id需要和item的back的id一致(front同理)
    app:swipeCloseAllItemsWhenMoveList="true"    //拖动listview时是否关闭拉开的item(有人建议是true,不然可能有问题)
    app:swipeFrontView="@+id/front"
    app:swipeMode="both"                                   //是否左右都能拉
    app:swipeOffsetLeft="0dp"                              //拉动距离
    app:swipeOffsetRight="0dp"  
    app:swipeOpenOnLongPress="false"                     //长按打开item
    />

    设置adapter:

    public class SwipeAdapter extends ArrayAdapter<String> {
    private LayoutInflater mInflater ;
    private List<String> objects ;
    private SwipeListView mSwipeListView ;
    public SwipeAdapter(Context context, int textViewResourceId,List<String> objects, SwipeListView mSwipeListView) {
    super(context, textViewResourceId, objects);
    this.objects = objects ;
    this.mSwipeListView = mSwipeListView ;
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null ;
    if(convertView == null){
    convertView = mInflater.inflate(R.layout.package_row, parent, false);
    holder = new ViewHolder();
    holder.mFrontText = (TextView) convertView.findViewById(R.id.example_row_tv_title);
    holder.mBackEdit = (Button) convertView.findViewById(R.id.example_row_b_action_3);
    holder.mBackDelete = (Button) convertView.findViewById(R.id.example_row_b_action_2);
    convertView.setTag(holder);
    }else{
    holder = (ViewHolder) convertView.getTag();
    }
    holder.mBackDelete.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    mSwipeListView.closeAnimate(position);
    mSwipeListView.dismiss(position);
    }
    });
    String item = getItem(position);
    holder.mFrontText.setText(item);
    return convertView;
    }
    class ViewHolder{
    TextView mFrontText ;
    Button mBackEdit,mBackDelete ;
    }
    }

    设置listener:

    class TestSwipeListviewListener extends BaseSwipeListViewListener {
    @Override
    public void onClickFrontView(int position) {
    // TODO Auto-generated method stub
    super.onClickFrontView(position);
    Toast.makeText(getApplicationContext(), "click:"+testdata.get(position), Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onDismiss(int[] reverseSortedPositions) {
    for(int position:reverseSortedPositions){
    //这里弹出的toast必须在前面,不然显示的是下一个item
    Toast.makeText(getApplicationContext(), "remove:"+testdata.get(position), Toast.LENGTH_SHORT).show();
    testdata.remove(position);
    }
    adapter.notifyDataSetChanged();
    }
    }

  • 相关阅读:
    哈工大中文篇章关系语料
    MongoDB学习笔记~关于官方驱动集成IQueryable之后的一些事
    MongoDB学习笔记~为IMongoRepository接口更新指定字段
    MongoDB学习笔记系列
    MongoDB学习笔记~为IMongoRepository接口添加了增删改方法,针对官方驱动
    MongoDB学习笔记~为IMongoRepository接口添加了排序和表达式树,针对官方驱动
    Android NDK入门实例 计算斐波那契数列二生成.so库文件
    Spring Autowire自动装配
    在gem5的full system下运行 alpha编译的测试程序 running gem5 on ubuntu in full system mode in alpha
    工厂三兄弟之抽象工厂模式(二)
  • 原文地址:https://www.cnblogs.com/jkx1229761162/p/4795513.html
Copyright © 2011-2022 走看看