You may choose to use a custom Dialog Fragment to do so.
First, get the global x & y position of the cell of the first table view that you clicked. From this post:
Rect myViewRect = new Rect();
myView.getGlobalVisibleRect(myViewRect);
float cx = myViewRect.exactCenterX();
float cy = myViewRect.exactCenterY();
Then, create a class that extends DialogFragment (let's call it SecondTableFragment
). To change the Dialog from your default Android style dialogs, you need to do a few things
Make the title disappear
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
Set the width of the Dialog to fit your second table view
@Override
public void onResume() {
getDialog().getWindow().setLayout([PARENT_LAYOUT_TYPE].LayoutParams.WRAP_CONTENT, [PARENT_LAYOUT_TYPE].LayoutParams.WRAP_CONTENT);
super.onResume();
}
Set the position of your dialog window above that of your clicked cell (this should most probably be done in onCreateDialog()
as well):
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.cx = cx; //x position
wmlp.cy = cy; //y position
For the logic behind filling out the Dialog view itself, you need to create a new layout file for the 2nd table layout (like you do for a new Activity) and inflate it and fill it up with relevant information like any other normal fragment. Make sure to pass in the x & y co-ordinates you want the dialog to be in when calling it's newInstance()
method. See Google's Documentation
Once everything's set up, you can then show a "2nd table Dialog" above the 1st TableLayout with the relevant information by using Fragment Manager (or ChildFragmentManager if you are already in a Fragment)
SecondTableFragment fragment = SecondTableFragment.newInstance(cx, cy, RELEVANT INFORMATION ...);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("secondTable");
if (prev != null) {
ft.remove(prev);
}
ft.add(fragment, "secondTable");
ft.addToBackStack(null);
ft.commitAllowingStateLoss();
fragment.setCancelable(false);