1

I want to do a random int that can be 0 or 1. No other options.

I want to check the int value, and if it equals to 1, then I want to switch between 2 TextViews places on the layout.

I know how to check the int value, but how can I switch the TextViews places?

3 Answers3

2

One of the things which you can do is declare two TextViews in which ever places you want them and give them the unique id values. Then based on your variable value, decide to show a textView with a given id.

CodePhobia
  • 1,315
  • 10
  • 19
1

UPDATE

You can also try this:

float text1x = text1.getX();
float text1y = text1.getY();

float text2x = text2.getX();
float text2y = text2.getY();

text1.setX(text2x);
text1.setY(text2y);

text2.setX(text1x);
text2.setY(text1y);

source

Here are some some ideas you can implement:

  • You can use List View and reorder the items
  • You can use .removeView(the view) then .addView(the view) to their parent
  • You can switch their text
  • You can create a copy if them which is invisible and reordered - so if int is 0 set View.Visible to the layout with text1 text2 and if it's 1 - View.GONE for the first layout and View.Visible for layout text2 text1
Community
  • 1
  • 1
0

Rather than switching the TextViews, swap the texts of the TextView.

Akash Singh
  • 748
  • 1
  • 6
  • 14