Coder Social home page Coder Social logo

calendarselector's Introduction

CalendarSelector

===

仿淘宝预订日历

sample_pic

功能描述:

根据从今天起的可选择天数跳转到日历选择列表页面,选择好预订日后在onActivityResult方法中得到年月日(格式为“年#月#日”)。

使用:

1 第一步跳转日历列表选择器

    Intent i = new  Intent(MainActivity.this, CalendarSelectorActivity.class);
    // 可选天数
	int days = 35;
	i.putExtra(CalendarSelectorActivity.DAYS_OF_SELECT, days);
	// 预订日期(可选)
	String order = "2014#11#11";
	i.putExtra(CalendarSelectorActivity.ORDER_DAY, order);
	startActivityForResult(i, 1);

2 第二步在onActivityResult方法中接收返回数据

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	super.onActivityResult(requestCode, resultCode, data);
	if (requestCode == 1 && resultCode == RESULT_OK) {
		String orderInfo = data.getStringExtra(CalendarSelectorActivity.ORDER_DAY);
		orderEt.setText(orderInfo);
	}
}

3 如果需要转换为Calendar

	// 正确转换方法:
	String[] info = orderInfo.split("#");
	Calendar c = Calendar.getInstance();
	c.set(Integer.valueOf(info[0]), Integer.valueOf(info[1]) - 1, Integer.valueOf(info[2]));

// 错误转换方法(因为2月没有30天):

c.set(Integer.valueOf(info[0]), Integer.valueOf(info[1]), Integer.valueOf(info[2]));

c.add(Calendar.MONTH, -1);

calendarselector's People

Contributors

lvning avatar

Watchers

James Cloos avatar KnowFly 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.