I created a component selectableListItem() that has a title, subtitle, and radio button icon but it shows differently on different android devices. On the emulator, it shows fine...on a real device, no radio button is showing on second item and the first item radio button is small. On another real device... the radio button on second item is very small while others are fine.
screenshoot another screenshot
Column {
FiveVerticalSpacer()
valuePoll.forEachIndexed { index, saveCustomerRequest ->
SelectionListItem(
index = index,
isSelected = saveCustomerRequest.title == onItemSelected.title,
title = saveCustomerRequest.title,
subTitle = saveCustomerRequest.description,
onClick = {
onItemSelected = saveCustomerRequest(
saveCustomerRequest.title,
saveCustomerRequest.description
)
}
)
Related
I am trying to create a list of items with a hidden button at the bottom. By default the button is not visible on the screen.
If a user scrolls to the bottom of the list the button should appear like it is the last item of the list.
I created illustrations to better visualize the desired behaviour:
Sketch 1: List with a few items
Sketch 2: List with a lot of items
I already tried the solution for a similar problem (https://stackoverflow.com/a/69196765/11720296) and added extra offset but unfortunately it didn't work.
Does somebody have an idea how to create this behaviour?
itemsIndexed will help in this case in following example I have used itemsIndexed in Lazycolumn it gives index which is visible to the user.
In this example I was trying to show some specific text only when first message is visible.
LazyColumn() {
itemsIndexed(tempListOfMessages) { index, localMessage ->
if (localMessage != null) {
SingleMessageView(
localMessageInfo = localMessage,
(index == 0)
)
}
}
}
when scroll that text scroll with first item.
Try this.
Scaffold { paddingValues ->
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = paddingValues
) {
...
}
}
I am trying to work on radio groups. I have an ok button which when clicked selects one item from four inflated radio button groups. My problem is that, when the user does not select an option from one of the groups, I have a null pointer exception.
Here is my selection code
private void getSelectedValuesAdults()
{
rl=(RelativeLayout)findViewById(R.id.activity_selections);
int id1 = ((RadioGroup)findViewById(R.id.KSradioGrp)).getCheckedRadioButtonId();
int id2 = ((RadioGroup)findViewById(R.id.KTradioGrp)).getCheckedRadioButtonId();
int id3 = ((RadioGroup)findViewById(R.id.KDradioGrp)).getCheckedRadioButtonId();
int id4 = ((RadioGroup)findViewById(R.id.KSoradioGrp)).getCheckedRadioButtonId();
stringChoice[0]= ((RadioButton)findViewById(id1)).getText().toString().contains(generalKid[0].getName())==true?generalKid[0].getName():generalKid[1].getName();
stringChoice[1]= ((RadioButton)findViewById(id2)).getText().toString().contains(generalKid[2].getName())==true?generalKid[2].getName():generalKid[3].getName();
stringChoice[2]= ((RadioButton)findViewById(id3)).getText().toString().contains(generalKid[4].getName())==true?generalKid[4].getName():generalKid[5].getName();
stringChoice[3]= ((RadioButton)findViewById(id4)).getText().toString().contains(generalKid[6].getName())==true?generalKid[6].getName():generalKid[7].getName();
genCost[0]= ((RadioButton)findViewById(id1)).getText().toString().contains(generalKid[0].getName())==true?generalKid[0].getCost()+5:generalKid[1].getCost()+5;
genCost[0]= ((RadioButton)findViewById(id2)).getText().toString().contains(generalKid[2].getName())==true?generalKid[2].getCost()+5:generalKid[3].getCost()+5;
genCost[0]= ((RadioButton)findViewById(id3)).getText().toString().contains(generalKid[4].getName())==true?generalKid[4].getCost()+5:generalKid[5].getCost()+5;
genCost[0]= ((RadioButton)findViewById(id4)).getText().toString().contains(generalKid[6].getName())==true?generalKid[6].getCost()+5:generalKid[7].getCost()+5;
}
The Ok button jumps to the method above. I have used if(id1==-1||id2==-1||id3==-1||id4==-1) callDialogMessage() just before the assignment to stringChoice[0] where callDialogMessage() is a message that lets you know you have not selected from a radio group but my app still crashes. What can I do? Any help will be highly appreciated
On click of OK button get selected radio button Id using radio group .You can refer the below code.
int selectedId =radioButtonGroup.getCheckedRadioButtonId();;
// find the radiobutton by returned id
RadioButton radioButton = FindViewById<RadioButton>(selectedId);
if(radioButton !=null)
{
//do things here
}
I am trying to update the background color of a Label inside a TableViewRow. I am using a View/Controller for the rows, creating them in code and appending them as an array to the TableView. Using onClick of the TableViewRow and Label.setBackgroundColor() inside the TableViewRow controller.
ExampleRow.xml
<TableViewRow id="exampleRow" class="exampleClass" onClick="exampleClick">
<Label id="exampleLabel" text="test" />
</TableViewRow>
ExampleRow.js
var test = 1;
function exampleClick(e) {
if(test == 1) {
$.exampleLabel.setBackgroundColor('#0f0');
test = 0;
} else {
$.exampleLabel.setBackgroundColor('#fff');
test = 1;
}
}
ExamplePage.xml
<TableView id="exampleTable" />
ExamplePage.js
var tableViewRows = [];
for(var i = 0; i < 5; i++) {
tableViewRows.push(
Alloy.createController('exampleRow', {}).getView()
);
}
$.exampleTable.setData(tableViewRows);
The problem is this does not work on the first page as soon as the app loads. If I scroll the TableViewRows outside of the screen and back in, the background color change works. If an alert box is popped up the background change works. But after first app load, the background color will not change. It also works if we use appendRow for each row, but this is substantially slower.
appendRow fix example:
for(var i = 0; i < 5; i++) {
$.exampleTable.appendRow(
Alloy.createController('exampleRow', {}).getView()
);
}
appending the rows individually sometimes fixes the bug (not every row), but for our list takes 5-8 seconds to display the table, rather than <1second using setData*
Example of the real app not working:
Example of the real app working:
This occurs after having an alert box displayed or scrolling the rows out and back in to the screen, or using appendRow for each row
Methods I have attempted to fix (did not fix):
using animations
removing the label then recreating and adding a new label in code
removing class from the TableViewRow
I am using Titanium SDK 5.0.2.GA and compiling on android 5.1.1.
Try to use click event of tableView instead of tableViewRow :
<TableView onClick="yourTableViewClickEvent"></TableView>
and then define what logic will be executed inside this function callback :
function yourTableViewClickEvent(e){
// access selected row
var currentSelectedRow = e.row;
// current selected Label we assume here that the row contain a label as first child (exactly what you have in your row definition
var currentLabel = currentSelectedRow.children[0]
// change label background color
currentSelectedRow.backgroundColor = "#0f0"
// You can even (i know it is no good to do that :)) test if the color is white or #0f0 like so
if(currentSelectedRow.backgroundColor == "#fff")
currentSelectedRow.backgroundColor = "#0f0"
else
currentSelectedRow.backgroundColor = "#fff"
}
I have one activity and here i have 100 buttons, i want that when i press Button 1 then press another Button the Button 1 should get unpressed.
i know i can make this with
if(Button1.isPressed()) {
Button2.setPressed(false);
Button3.setPressed(false);
Button4.setPressed(false);
Button5.setPressed(false);
Button6.setPressed(false);
Button7.setPressed(false);
Button8.setPressed(false);
......................... }
else { do nothing }
.... BUT!
it's too much code
Coders will kill me or will just laugh on me.
any ideas?
maybe there is a way to unpress the all buttons from the activity?
Not the prettiest solution ever, but you could make an OnClickListener like this:
View.OnClickListener listener = new View.OnClickListener() {
public void onClick(View v) {
ViewGroup parent = (ViewGroup) v.getParent();
for (int i = 0; i < parent.getChildCount(); i++) {
View current = parent.getChildAt(i);
if (current != v && current instanceof Button) {
((Button) current).setPressed(false);
}
}
((Button) v).setPressed(true);
}
}
and attach it to all of your buttons.
Then, whenever a button is clicked, it will iterate over all views that are in the same layout (or actually, view group) as the clicked button, and, for any of those views that are buttons except for the clicked button, it will call setPressed(false).
Note that this only works out of the box if all the buttons are in the same layout. If they are in nested layouts, you will have to adapt it a little.
Off topic: What do you need 100 buttons for? That's a lot of buttons. You may want to redesign your user interface
Ok so instead of looping through all the buttons on over and over again when one button is pressed, you can just store a variable which stores the button number of the button that was last pressed. Now, when the second button is pressed, disable the button that was pressed earlier, you get its index from the saved variable, enable the button that was pressed and store its index in the variable.
Heres an example pseudo code to give you and idea:
int buttonLastPressed = 0;
void onButtonClick(Button buttonPressed){
if(buttonLastPressed != 0){
disableButton(buttonLastPressed);
enableButton(buttonPressed);
buttonLastPressed = buttonPressed.getIndex()
}
}
Saves you from looping through each and every button to disable it.
Define id of button 1 to 100
When press button occurs save it's id in some member variable like previous_pressed
Before updating a previous_pressed value find and unpress previous pressed button like this
Button previous_pressed_button = (Button) findViewById(previous_pressed);
Now you have the previous pressed button, So upress it or whatever.
Ok im making app and it have 15 button's and 6 textview's.I want when I press first button to change value of first textview(value is "") to something (number one for example).But problem is when i press second button if first textview is already set to some value to set set second textview to second value.
If you need something else ask in comments (sorry for bad English)
here is what I was doing(this is under onclick)when i press second button
if(textview1.equals("1")){
textview2.setText("2");}
else if (textview1.equals("")){
textview1.setText("2");
}
It sounds like you wish to show last 6 buttons pressed.
Store all pressed buttons in a List (i.e. LinkedList) of size 6. Initially, it will be empty.
Then whenever any button is pressed do two things:
1) add it to the List and delete old elements if size exceeds six.
2) set button values from List.
Second step can be achieved like this:
// all TextViews should be in a list
private List<TextView> textViews;
// declare as field
private List<String> memoryQueue = new ArrayList<String>();
public void update() {
//set fields for the pressed buttons
for (int i=0; i<6 && i<memoryQueue.size(); i++) {
String text = memoryQueue.get(i);
textViews.get(i).setText(text);
}
// set empty fields
for (int i = memoryQueue.size(); i<6; i++) {
textViews.get(i).setText("");
}
}
This code snippet assumes that you store your TextViews in a List.
And Easiest way to keep track of last six button:
public void buttonPressed(Button button) {
//get text based on your button
String text = button.getText();
if (memoryQueue.contains(text)) {
return;
}
memoryQueue.add(text);
if (memoryQueue.size() > 6) {
memoryQueue.remove(0);
}
}
Since you're concerned with the text inside of your text view, you should be using the object's getText method:
if( textview1.getText().equals("1") ){ // Edited
textview2.setText("2");
} else if (textview1.getText().equals("")){ //Edited
textview1.setText("2");
}
At first, you have to get the String text from TextView using getText() method then you can compare that String with another String. Now, change your condition as follows...
if(textview1.getText().toString().equals("1")){
textview2.setText("2");}
else if (textview1.getText().toString().equals("")){
textview1.setText("2");
}