Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically defining and using selectors

I have a ListView which has custom elements inside of it. I want to create selectors for each of those elements. Selectors themselves will not be very complicated because they need to handle only background color while item is hovers/selected/etc. However colors for those selectors have to come from external source that is I need to be able to set them from variables, so some simple static code will not do.

  1. How to define sector with all it`s parameters programmatically?
  2. How to assign that selector programmatically to a specific view?
like image 408
PovilasID Avatar asked Oct 05 '12 21:10

PovilasID


People also ask

What are dynamic selectors?

Dynamic selector : During RPA flow, most of the values are static and predetermined. The ability to enter these values manually of programmatically is the use of a dynamic selector. For example, select a date in date selector control on a website.

What is the use of selectors in UiPath?

One of the ways in which UI elements can be identified is by using their position on the screen, but this can be unreliable. To overcome this problem, UiPath Studio uses what we call selectors. These store the attributes of a graphical user interface element and its parents, in the shape of an XML fragment.

What are selectors in RPA?

Selectors are mechanisms that assist in identifying and selecting an element from an application with a graphical user interface (GUI). These elements can be windows, combination boxes, push buttons, among others. Elements can also be called controls.


2 Answers

StateListDrawable states = new StateListDrawable();
int yourBackgroundColor = Color.parseColor("#FFFFFF");
// Add specific color when your view has state 'pressed'
states.addState(new int[] {android.R.attr.state_pressed}, new ColorDrawable(yourBackgroundColor));
// Add other states wanted and associated drawable
// ...
// As StateListDrawable extend Drawable, you can use it as background for exemple       
yourView.setBackground(states);

You can add states as many as you want into your StateListDrawable (List of states available: http://developer.android.com/guide/topics/resources/color-list-resource.html). For each states combination you can set specific and dynamic drawable.

You can specify multiple states to match for a drawable

states.addState(new int[] { -android.R.attr.state_focused,
                            android.R.attr.state_selected,
                            -android.R.attr.state_pressed}, ColorDrawable(yourBackgroundColor));

This time the color will be applied if your view is not focused, is selected and is not pressed.

like image 102
Cyril Maitre Avatar answered Oct 03 '22 14:10

Cyril Maitre


StateListDrawable states = new StateListDrawable();
int yourBackgroundColor = Color.parseColor("#FFFFFF");
// Add specific color when your view has state 'pressed'
states.addState(new int[] {android.R.attr.state_pressed}, 
        new ColorDrawable(yourBackgroundColor));
// Add other states wanted and associated drawable
// ...
// As StateListDrawable extend Drawable, you can use it as background for exemple       
yourView.setBackground(states);
like image 37
Nazmul Avatar answered Oct 03 '22 14:10

Nazmul