How do you select index of the list particular value?

47
June 12, 2019, at 10:10 AM

I have a list element and when user types 1 it clicks on index 0 element, when user types 2 it clicks on index 1 element, when user types 3 it selects index 2 element and when user types 4 it clicks on index 3 element.. How would you write the method in correct way?

AndroidFinBy(id="example") List list;

 public boolean list(int list_view) {
    if(list_view == 1) {
        list.get(0).click();
    }else if(list_view ==2){
        chipList.get(1).click();
    }else if(list_view ==3){
        list.get(2).click();
    }else if(list_view ==4){
         list.get(3).click();
    return true;
    }
    return false;

My code does not work keeps selecting the wrong element?

Answer 1
public boolean list(int list_view) {
    if(list.size() >= list_view && list_view > 0) {
        list.get(list_view - 1).click();
        return true;
    }
    return false;
}
READ ALSO
How to insert mutliple where clauses into an SQL string

How to insert mutliple where clauses into an SQL string

I'm using an Azure Cosmos NoSQL database with SQL syntaxHow do I create an SQL string that can dynamically add more WHERE statements? For example, I want to be able to not have to code in "WHERE f

19
Spring framework and Project Loom (Fibers) [on hold]

Spring framework and Project Loom (Fibers) [on hold]

Is there any plan to integrate Project Loom (Fibers) with Spring Framework?

34
How can I access “message” or “added”? It is in JSON format

How can I access “message” or “added”? It is in JSON format

I need to print "message" and "added" from this JSON in Java

39
How to configure NatTable FilterComboBox to have a different DataProvider for each column

How to configure NatTable FilterComboBox to have a different DataProvider for each column

In my NatTable I am using a ComboBoxFilterRowHeaderComposite similar to ExcelLikeFilterRowCustomTypesExampleIt works fairly well however the combo box filtering adds too many items in large tables to allow for easy filtering

39