Skip to content

feat(android): new widget: Ti.UI.Android.RadioButtons #14192

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Mar 22, 2025

Currently we don't have native RadioButtons! This PR will add a new widget Ti.UI.Android.createRadioButtons().

Screenshot_20250322_173934

Properties:

  • labels: Array of strings
  • selectedIndex
  • color
  • tintColor

Events:

  • click: returns index
var win = Ti.UI.createWindow({});
var radioButtons = Ti.UI.Android.createRadioButtons({
	labels: ["option 1", "option 2", "option 3"],
	top: 10,
	left: 10,
	selectedIndex: 1
})
var btn = Ti.UI.createButton({
	title: "select item 2",
	bottom: 10
});
var btn2 = Ti.UI.createButton({
	title: "change labels",
	bottom: 60
});
var btn3 = Ti.UI.createButton({
	title: "change color",
	bottom: 110
});
btn.addEventListener("click", function(){
	radioButtons.selectedIndex = 1;
	console.log(radioButtons.selectedIndex)
})
btn2.addEventListener("click", function(){
	radioButtons.labels = ["new option 1", "new option 2", "new option 3", "new option 4"];
})
btn3.addEventListener("click", function(){
	radioButtons.color = "yellow";
	radioButtons.tintColor = "yellow"
})
radioButtons.addEventListener("click", function(e){
	alert("Item " + e.index + " was clicked. Value: " + radioButtons.labels[e.index]);
	console.log("Index: " + radioButtons.selectedIndex);
})
console.log(radioButtons.selectedIndex);

win.add([radioButtons, btn, btn2, btn3]);
win.open();

Todo:

  • add it to Alloy [separate PR afterwards]

@Max87ZA
Copy link

Max87ZA commented Mar 25, 2025

is there something like this on iOS? Otherwise I'll move it to the Android namespace
I don't think so, afaik iOS never supported RadioButtons(only macOS does), so every app that has it they created/emulated from scratch using Button/Image/etc
I checked guidelines recently and instead of RadioButton we should use Switch

@m1ga
Copy link
Contributor Author

m1ga commented Mar 25, 2025

Ah, good to know. I'll move it to the Android namespace.

@m1ga m1ga changed the title feat(android): new widget: Ti.UI.RadioButtons feat(android): new widget: Ti.UI.Android.RadioButtons Apr 3, 2025
@m1ga
Copy link
Contributor Author

m1ga commented Apr 3, 2025

Update:

  • moved it into Ti.UI.Android
  • added apidocs
  • added color and tintColor

@m1ga m1ga marked this pull request as ready for review April 3, 2025 16:30
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

Successfully merging this pull request may close these issues.

2 participants