Coder Social home page Coder Social logo

fanpulltorefresh's Introduction

下拉刷新(安能饭否)

##Useage ###Layout xml

	<com.fanpulltorefresh.PullToRefresh
		android:id="@+id/pullDownView1" android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		>
		<!--content-->
		<ListView android:id="@+id/listview1" android:layout_width="fill_parent"
			android:layout_height="fill_parent"></ListView>
	</com.fanpulltorefresh.PullToRefresh>

###Activity

public class MainActivity extends Activity implements
		PullToRefresh.UpdateHandle {
	PullToRefresh refresh;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		refresh = (PullToRefresh) this.findViewById(R.id.pullDownView1);
		refresh.setUpdateHandle(this);
		ListView view = (ListView) this.findViewById(R.id.listview1);
		view.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_expandable_list_item_1, getData()));
	}

	private List<String> getData() {

		List<String> data = new ArrayList<String>();

		for (int i = 1; i < 30; i++) {
			data.add("测试数据" + i);
		}

		return data;
	}

	@Override
	public void onUpdate() {
		new MyThread(handler).start();
	}

	class MyThread extends Thread {
		private Handler handler;

		public MyThread(Handler handler) {
			this.handler = handler;

		}

		@Override
		public void run() {
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {

				e.printStackTrace();
			}
			Message msg = handler.obtainMessage();
			handler.sendMessage(msg);
			super.run();
		}

	}

	private final Handler handler = new Handler(Looper.getMainLooper()) {
		public void handleMessage(Message msg) { // 处理Message,更新ListView
			SimpleDateFormat formatter = new SimpleDateFormat(
					"yyyy年MM月dd日   HH:mm:ss     ");

			Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
			String str = formatter.format(curDate);
			refresh.endUpdate(str);
		}
	};
}

fanpulltorefresh's People

Contributors

dodola avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.