I need to use a TextSwitcher
component with the intention that when the user moves this TextSwitcher
to the right as well as to the left the text of the same will be changed.
For this I created a variable of type String[]
and stored 5 values, and I used the OnTouch
event in the TextSwitcher
component, but with the following code that I will post below the text is not changed, even by giving a ArrayOfBounds
error because I did not deal in the size of the Strings array.
What would be the best way to switch texts?
tsIntroduction.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// Variaveis declaradas no topo da aplicação
initialX = event.getX();
initialY = event.getY();
case MotionEvent.ACTION_UP:
float finalX = event.getX();
float finalY = event.getY();
if (initialX < finalX) {
pos =+ 1;
}
if (initialX > finalX) {
pos =- 1;
}
}
// Varíavel pos declarada no inicio da aplicação para pegar a posição atual
tsIntroduction.setText(descriptions[pos]);
return true;
}