Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding singledatepicker #72

Closed
christianCallelero opened this issue Jun 20, 2017 · 4 comments
Closed

Adding singledatepicker #72

christianCallelero opened this issue Jun 20, 2017 · 4 comments

Comments

@christianCallelero
Copy link

Hi I would like to add a feature wherein we can use this library to somewhat disable the two tabs (From,To). So we can use it for just getting a single date. However I'm new to library cloning so can anyone help me with this? I know how to clone but my idea for adding this as a module is limited. Thanks

@PunchyRascal
Copy link

In this case use the native Android date picker :)

https://developer.android.com/guide/topics/ui/controls/pickers.html

@christianCallelero
Copy link
Author

Yeah its possible but I want to keep the design consistent to all my datepicker. Anyway I was able to clone the project and create an option for single date. closing this thread now.

@RamithRD
Copy link

@christianCallelero Hi, can you share the single date selection option you implemented?

@dmz9
Copy link

dmz9 commented Mar 4, 2019

@christianCallelero Hi, can you share the single date selection option you implemented?

maybe it's late, but anyway: you could just subclass the datepicker, and override #onViewCreated.
use findViewById(android.R.id.tabs) to get "tabs" layout at hands and make it's visibility = GONE, so it is not displayed anymore. works with config change/screen rotation, because when view recreated - tabs are "GONE" again.
the ondatechange listener stays the same, except you do not use "end" dates, since user intacts with the first tab only.

probably you need to recreate static constructors too (#newInstance methods)

internal class OnlyDatePickerDialog : com.borax12.materialdaterangepicker.date.DatePickerDialog() {
	override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
		super.onViewCreated(view, savedInstanceState)
// hide tabs heading so user cant see it
		view?.findViewById<TabWidget>(android.R.id.tabs)?.let{
			it.visibility = View.GONE
		}
	}
// static constructors are not inherited in kotlin, so recreate them
	companion object {
		fun newInstance(
			callBack: OnDateSetListener, year: Int,
			monthOfYear: Int,
			dayOfMonth: Int
		): OnlyDatePickerDialog {
			val ret = OnlyDatePickerDialog()
			ret.initialize(callBack, year, monthOfYear, dayOfMonth)
			return ret
		}

		fun newInstance(
			callBack: OnDateSetListener, year: Int,
			monthOfYear: Int,
			dayOfMonth: Int,
			yearEnd: Int,
			montOfYearEnd: Int,
			dayOfMonthEnd: Int
		): OnlyDatePickerDialog {
			val ret = OnlyDatePickerDialog()
			ret.initialize(callBack, year, monthOfYear, dayOfMonth, yearEnd, montOfYearEnd, dayOfMonthEnd)
			return ret
		}
	}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants