So this is what I ended up doing if anyone faces a similar problem:
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) {
return true;
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//code goes here
}
});
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.dimAmount=0.0f;
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
dialog.getWindow().setAttributes(wmlp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.show();
return true;
}
});
The answer is based on Show AlertDialog in any position of the screen so thanks a lot to the original author!