Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSlideListView = ((SlideListView) findViewById(R.id.list_view));
    mTestData = new ArrayList<String>();
    randomCreateTestData();
    mAdapter = new SlideAdapter(this, mTestData);

    TextView headView1 = new TextView(this);
    headView1.setHeight(60);
    TextView headView2 = new TextView(this);
    headView2.setHeight(60);
    TextView footerView1 = new TextView(this);
    footerView1.setHeight(60);
    headView1.setText("这是HeaderView1");
    headView2.setText("这是HeaderView2");
    footerView1.setText("这是FooterView1");
    mSlideListView.addHeaderView(headView1);
    mSlideListView.addHeaderView(headView2);
    mSlideListView.addFooterView(footerView1);

    mSlideListView.setAdapter(mAdapter);

    mSlideListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String s = (String) parent.getAdapter().getItem(position);
            if (!TextUtils.isEmpty(s)) {
              Toast.makeText(MainActivity.this, "OnItemClick:" + s, Toast.LENGTH_SHORT).show();
            }
          }
        });

    mSlideListView.setOnScrollListener(
        new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_IDLE) {
              Log.d("roamer", "no");
            } else {
              Log.d("roamer", "scroll");
            }
          }

          @Override
          public void onScroll(
              AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}
        });
  }
 /**
  * Init ListView
  *
  * @param attrs AttributeSet
  */
 private void init(AttributeSet attrs) {
   if (attrs != null) {
     TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SlideListView);
     mAnimationTime = styled.getInteger(R.styleable.SlideListView_slideAnimationTime, 0);
     mSlideMode =
         SlideMode.mapIntToValue(styled.getInteger(R.styleable.SlideListView_slideMode, 0));
     mSlideLeftAction =
         SlideAction.mapIntToValue(
             styled.getInteger(R.styleable.SlideListView_slideLeftAction, 0));
     mSlideRightAction =
         SlideAction.mapIntToValue(
             styled.getInteger(R.styleable.SlideListView_slideRightAction, 0));
     styled.recycle();
   }
   mTouchListener = new SlideTouchListener(this);
   // You can't use setOnTouchListener() in your own code
   setOnTouchListener(mTouchListener);
   // You can use setOnScrollListener() in your own code
   setOnScrollListener(mInnerOnScrollListener);
   // You can use setOnItemClickListener() in your own code
   setOnItemClickListener(mInnerOnItemClickListener);
 }