Issue
On my TableLayout, one TableRow has a TextView, and another has a Spinner. When the user checks a checkbox, I want to swap the positions of these 2 views. The Spinner needs to move to the position of the TextView, and the TextView needs to move to the position of Spinner.
Animation doesn't matter. The preference would be that it happens instantly, but I could make it a super-fast animation if necessary.
I have been surprised at how much trouble I've had trying to locate a solution to this problem :/ On a similar note, the Android dev ref could really use some simple examples a la the MSDN library.
Thanks!
Solution
Here is the code I ended up using to swap the views:
import android.widget.TableRow;
TableRow trI = (TableRow) findViewById(R.id.tr_input_row);
TableRow trO = (TableRow) findViewById(R.id.tr_output_row);
View v1 = (View) findViewById(R.id.View1);
View v2 = (View) findViewById(R.id.View2);
if (isInput()) {
trO.removeView(v1);
trI.removeView(v2);
trO.addView(v2);
trI.addView(v1);
} else {
trO.removeView(v2);
trI.removeView(v1);
trO.addView(v1);
trI.addView(v2);
}
In my case, the views were in two different rows of a TableLayout. I'm using TableRow because it is the type of the parent of the views I want to swap. I assume this could be updated to be whatever type of parent the target views have.
Answered By - jwatts1980
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.