ok, here is the story...
I have 3 textfield for user to select....
[textfield A][textfield B][textfield C]
and a confirm button, the user need to add three textfield, after that , the user need to click the confirm button.... but based on different select order, the result is different, for example:
A>B>C, I will show red.
When the user select in this order:
B>A>C I will show green.
When the user select in this order:
C>B>A I will show the color blue....
based on different user select order, it will show different color....
But the question is, when I add more and more textfield, how can I implement this logic?
First, I design to have an array , when the user select one textfield, I store the textfield id to array, when user select the second one, I will store in the array, until the user click confirm, I read back the array to display the color....
But I think it will become very big & messy when more and more textfield is added, any better ideas? Thank you.
It's a bit of a hack, but what I'd be inclined to do is store the selections in a string that gets appended to each time (starting with empty string of course), trimming to the rightmost x characters. Then you can do a simple switch/case statement to determine the color. For example (C# fragments, sort of):
string selectStr = string.Empty;
void Select(string btn) {
selectStr += btn;
selectStr = selectStr.Remove(0, btn.Length - 3);
}
void Confirm() {
switch (selectStr) {
case "ABC" : /* make red */ break;
case "BAC" : /* make green */ break;
// etc.
}
}
Related
I am writing an UI test case, in which I need to perform an action, and then on the current page, scroll the only UITableView to the bottom to check if specific text shows up inside the last cell in the UITableView.
Right now the only way I can think of is to scroll it using app.tables.cells.element(boundBy: 0).swipeUp(), but if there are too many cells, it doesn't scroll all the way to the bottom. And the number of cells in the UITableView is not always the same, I cannot swipe up more than once because there might be only one cell in the table.
One way you could go about this is by getting the last cell from the tableView. Then, run a while loop that scrolls and checks to see if the cell isHittable between each scroll. Once it's determined that isHittable == true, the element can then be asserted against.
https://developer.apple.com/documentation/xctest/xcuielement/1500561-ishittable
It would look something like this (Swift answer):
In your XCTestCase file, write a query to identify the table. Then, a subsequent query to identify the last cell.
let tableView = app.descendants(matching: .table).firstMatch
guard let lastCell = tableView.cells.allElementsBoundByIndex.last else { return }
Use a while loop to determine whether or not the cell isHittable/is on screen. Note: isHittable relies on the cell's userInteractionEnabled property being set to true
//Add in a count, so that the loop can escape if it's scrolled too many times
let MAX_SCROLLS = 10
var count = 0
while lastCell.isHittable == false && count < MAX_SCROLLS {
apps.swipeUp()
count += 1
}
Check the cell's text using the label property, and compare it against the expected text.
//If there is only one label within the cell
let textInLastCell = lastCell.descendants(matching: .staticText).firstMatch
XCTAssertTrue(textInLastCell.label == "Expected Text" && textInLastCell.isHittable)
Blaines answer lead me to dig a little bit more into this topic and I found a different solution that worked for me:
func testTheTest() {
let app = XCUIApplication()
app.launch()
// Opens a menu in my app which contains the table view
app.buttons["openMenu"].tap()
// Get a handle for the tableView
let listpagetableviewTable = app.tables["myTableView"]
// Get a handle for the not yet existing cell by its content text
let cell = listpagetableviewTable.staticTexts["This text is from the cell"]
// Swipe down until it is visible
while !cell.exists {
app.swipeUp()
}
// Interact with it when visible
cell.tap()
}
One thing I had to do for this in order to work is set isAccessibilityElement to true and also assign accessibilityLabel as a String to the table view so it can be queried by it within the test code.
This might not be best practice but for what I could see in my test it works very well. I don't know how it would work when the cell has no text, one might be able to reference the cell(which is not really directly referenced here) by an image view or something else. It's obviously missing the counter from Blaines answer but I left it out for simplicity reasons.
Here is the case : i have 4 radioButtons that are not members of a radioGroup. Thats because RadioGroup places children in vertical order by default and cannot place them relative to each other.Right now , i am check all the radioButtons. What i want to achieve is to control their checked state , so that when one is checked(true) the others checked state is set automatically to false. There widgets are independent layout elements , so i guess i have to find a way to group them all together. I tried it by coding 4 RadioButton variables with a simple if..else if function using isChecked and setChecked built-in methods. Then i tried grouping them in an Radiobutton[] array and looping to the array.length with a switch-case loop. Nothing works.
Stack for 2 days now. Any help appreciated.
Thanks for reply , i explain further. I have 4 imageViews and 4 radioButtons exactly below each one , in a RelativeLayout parent , so that the user can make a choise which image he prefers. The imageViews are not vertically placed , so are the radioButtons. Thats why i dont want to use radioGroup. I could use LinearLayout and place imageViews in vertical orientation and have the radioButtons in a group just aside them. Every radioButton checked state is false by default and when i check it , becomes true. The problem is that i can check all of the radioButtons . What i want is when i select one RadioButton , the others are automatically unchecked , so that only one may be checked at any time.
Here is the snippet:
private RadioButton rbtnWater;
private RadioButton rbtnRoad;
private RadioButton rbtnBoy;
private RadioButton rbtnLeft;
rbtnWater = (RadioButton) findViewById(R.id.rbtnWater);
rbtnRoad = (RadioButton) findViewById(R.id.rbtnRoad);
rbtnBoy = (RadioButton)findViewById(R.id.rbtnBoy);
rbtnLeft = (RadioButton) findViewById(R.id.rbtnLeft)
//method called at onClick attribute (XML)
public void checkState(View v) {
if (rbtnWater.isChecked()) {
rbtnLeft.setChecked(false);
rbtnBoy.setChecked(false);
rbtnRoad.setChecked(false);
}
else if (rbtnLeft.isChecked()) {
rbtnBoy.setChecked(false);
rbtnWater.setChecked(false);
rbtnRoad.setChecked(false);
}
else if (rbtnBoy.isChecked()) {
rbtnWater.setChecked(false);
rbtnRoad.setChecked(false);
rbtnLeft.setChecked(false);
}
else if (rbtnRoad.isChecked()) {
rbtnWater.setChecked(false);
rbtnBoy.setChecked(false);
rbtnLeft.setChecked(false);
}
}
It not really clear what is not working, please add details
That being said I suggest you change the technique and use a RadioGroup anyway, just extend it and modify to what you need or take it's source code from AOSP and instead of having it extend a LinearLayout you can extend something else you would rather work with
Is there any way i can hide HOT columns from javascript?
The requirement is such that the column to hide will come as a parameter in javascript and based on that the respective column will show hide accordingly.
The HOT has rowHeaders and colHeaders and the data with 20 columns.
Please advise.
OUTDATED SOLUTION
Ok I founnd a possible solution. I tested it out on my own system but it's actually quite simple.
You should be using a customRenderer in your columns option. Read up about this if you aren't already. The idea is that you're giving each cell its own renderer. In this custom function, you can do something like this:
var colsToHide = [3,4,6]; // hide the fourth, fifth, and seventh columns
function getCustomRenderer() {
return function(instance, td, row, col, prop, value, cellProperties) {
if (colsToHide.indexOf(col) > -1) {
td.hidden = true;
} else {
td.hidden = false;
}
}
}
What this renderer does is hide the cells that the var colsToHide specify. All you do now is add a DOM element that lets the user pick which and so every time the table gets rendered (which happens basically after any change, or manually triggered need be), the cells in the columns specified will be hidden, keeping the data array intact like you described. And when not in colsToHide they are re-rendered so make sure you get that working as well.
Here I implemented it with very basic functionality. Just enter the index of a column into the input fields and watch the magic happen.
http://jsfiddle.net/zekedroid/LkLkd405/2/
Better Solution: handsontable: hide some columns without changing data array/object
I have a custom drawn combobox with style CBS_DROPDOWNLIST and CBS_OWNERDRAWVARIABLE I can draw the items of the dropdownlist ok but whe user select an item it is drawn in the combobox static part [the part of combo that stay visible after selecting item and show the selection], I want to give it a custom text like in the following image
But I can't determine it I found a code like this
if(DrawItemStruct.CtlType == ODT_COMBOBOX)//the static part of the combo
DrawComboText(pDC, DrawItemStruct.itemID, &DrawItemStruct.rcItem);
else//the rest items
{
// Copy the text of the item to a string
char sItem[256];
GetString(sItem, DrawItemStruct.itemID);
biDrawText(pDC, sItem, -1, &DrawItemStruct.rcItem, f | DT_VCENTER | DT_SINGLELINE);
}
but when I used it I get all the items has CtlType == ODT_COMBOBOX, when I debugged the above code It return ODT_COMBOBOX for the static part, and for items of the drop down list it return ODT_LISTBOX.
I want to know how to fix this problem, how to detect that I'm drawing the static part or a regular item in the dropdown list?
I just check the state for ODS_COMBOBOXEDIT. If ifthe dcumentation says that this flag is set for the edit Control, it works for the drop down list to.
I have checked combo box implementation like you that works in the sane way.
bool bDrawStaticControl = (pDIS->itemState & ODS_COMBOBOXEDIT)!=0;
I have the following code which allows the columns in my table to sort by ascending or descending order.
protected void setSortColumn(GridPanelColumn gridPanelColumn, TableColumn column) {
table.setRedraw(false);
// check if already selected
if (sortGridPanelColumn != null && sortGridPanelColumn == gridPanelColumn) {
// toggle sort order
sortAscending = !sortAscending;
} else {
// set new sort column
sortGridPanelColumn = gridPanelColumn;
sortAscending = false;
table.setSortColumn(column);
}
// set sort direction
table.setSortDirection(sortAscending ? SWT.UP : SWT.DOWN);
// refresh table
tableViewer.refresh();
table.setRedraw(true);
}
The only problem is that when the user clicks on the column header to sort, the arrow causes the column name to dot out (ex: Ccy..^ ) instead of (CCy1 Amount). Is there any way to turn off the showing of the arrows? I would rather not have to bother with resizing my grid columns just to accommodate for the arrows so that the dots don't form..
Any ideas on how to do this?
Simple! Just do not do
table.setSortDirection(sortAscending ? SWT.UP : SWT.DOWN);
When you call this method, you're just telling SWT which image to use. Without it, the sorting still works, but the arrows do not show.