ListView实现Item上下拖动交换位置 并且实现下拉刷新 上拉加载更多
package com.example.ListViewDragItem; import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ArrayAdapter;
import com.example.ListViewDragItem.refreshlist.CustomDragListView;
import com.example.ListViewDragItem.refreshlist.XListView; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; public class MyActivity extends Activity implements CustomDragListView.OnChangeListener, XListView.IXListViewListener {
private CustomDragListView customDragListView;
private ArrayAdapter adapter; private List<String> list = new ArrayList<String>(); /**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
InitList();
customDragListView = (CustomDragListView) findViewById(R.id.customDragListView);
adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
customDragListView.setAdapter(adapter);
customDragListView.setOnChangeListener(this);
customDragListView.setXListViewListener(this);
customDragListView.setPullLoadEnable(true);
// customDragListView.setPullRefreshEnable(true);
} private void InitList() {
for (int i = ; i <= ; i++) {
list.add("zhangSan" + i + i + i + i + i + i);
}
} /**
* item交换事件
*/
@Override
public void onMove(int from, int to) {
int headerCount = customDragListView.getHeaderViewsCount();
if (to - headerCount < list.size()
&& from - headerCount < list.size()) {
Collections.swap(list, from - headerCount, to - headerCount);
adapter.notifyDataSetChanged();
}
} @Override
public void onUp() { } /**
* listView刷新事件
*/
@Override
public void onRefresh() {
customDragListView.stopRefresh();
} /**
* listView加载更多事件
*/
@Override
public void onLoadMore() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
customDragListView.stopLoadMore();
}
}, );
}
}
震动权限:
<uses-permission android:name="android.permission.VIBRATE"/>