본문 바로가기
프로그래밍 놀이터/안드로이드, Java

[android] PullToRefreshListView up pull, down pull distinguish

by 돼지왕 왕돼지 2014. 2. 25.
반응형


 android, PullToRefreshListView up pull, down pull distinguish

 


[android] PullToRefreshListView up pull, down pull distinguish


public class MainActivity extends Activity {


private PullToRefreshListView mPtrlv;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView( R.layout.activity_main );


initListView();

}


private Handler mHandler = new Handler();

private Runnable mRunnable = new Runnable() {

@Override

public void run() {

mPtrlv.onRefreshComplete();

}

};

private void initListView(){

mPtrlv = (PullToRefreshListView) findViewById( R.id.cardlist );

mPtrlv.setOnRefreshListener( new OnRefreshListener2<ListView>() {

@Override

public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {

waitAndFinishRefresh();

}


@Override

public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

waitAndFinishRefresh();

}

});

}

private void waitAndFinishRefresh(){

new Thread( new Runnable() {

@Override

public void run() {

try{ 

Thread.sleep( 2000 );

mHandler.post( mRunnable );

} catch( Exception e ){ }

}

}).start();

}

}






반응형

댓글