You could simply define a TableView
with just one TableRow
(or as many as you need) and set a onClickListener
for each of those View
s inside the TableRow
, which would make that on any click, the selected View
would expand itself.
I don't know whether you'll have a static number of View
s inside that row or you'll construct them dynamically, but this should work for any of them, the real "work" here about populating that row.
Once you have your row of View
s, simply declare an onClickListener()
on each of them. For example, this should be enough:
OnClickListener myListener = new OnClickListener() {
@Override
public void onClick(final View v) {
v.setVisibility(View.VISIBLE);
}
};
And as the onClick
event for all of your items inside the TableRow
:
for (View v : myTableRowViews)
v.setOnClickListener(myListener);
This has a disadvantage: You can know which View
has been clicked for selection, but natively you cannot know which has been deselected, so you'll need to keep track of the last selected tab declaring a class-wide variable and setting it each time onClick()
is fired, so your listener will become something like this:
// In your class declare a variable like this
View lastSelected = null;
OnClickListener myListener = new OnClickListener() {
@Override
public void onClick(final View v) {
if (lastSelected != null)
lastSelected.setVisibility(View.GONE);
v.setVisibility(View.VISIBLE);
lastSelected = v;
}
};
Additionally, you can set an animation to the effect to make it more attractive, but mainly this is the idea.
One last thing: To make it work this way you'll need to set the layout_height
of both your TableRow
and the View
items inside, so it may expand afterwards when you set the additional part as visible. Also, to make it look good all of your View
s will have to be the same height (both in the reduced and extended state).