Reputation: 64
i have a Barrier in activity_constraint_layout, and want change it's type based some data from network, but setType(int type) is not work.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_constraint_layout)
clContainer = findViewById(R.id.clContainer)
// worked here
val barrier = findViewById<Barrier>(R.id.barrier)
barrier.type = Barrier.START
clContainer.setOnClickListener {
// do not work here
barrier.type = Barrier.END
}
}
Upvotes: 0
Views: 31
Reputation: 62831
The statement barrier.type = Barrier.END
executes the following withing the Barrier class:
public void setType(int type) {
mIndicatedType = type;
}
As you can see, it only sets the value of a variable. You also need to request a layout as follows:
clContainer.setOnClickListener {
// do not work here
barrier.type = Barrier.END
barrier.requestLayout()
}
Once you do this, you should see the effect you want.
Upvotes: 1