I’m creating N buttons in a for loop witch an OnClickListener each one. The user is able to click each button and set a number. After that, I want a TextView showing the number just over the button and in the middle of it.

This is just what I want. The gray background is the button, and the number is the TextView.
The code I have right now:
for (int toShow = 0; toShow < nShips; toShow++)
{
btn = new Button(this);
btn.setBackgroundResource(shipDrawable.get(ima));
btn.setLayoutParams(params);
row[pos].addView(btn);
btn.setId(shipId.get(ima));
btn.setOnClickListener(listeners);
if (row[pos].getChildCount() == 3) pos++;
ima++;
}
I tried using this inside the for loop:
float x = btn.getX(), y = btn.getY();
TextView level = new TextView(this);
level.setText("5");
level.setX(x); level.setY(y);
But didn’t work. What can I use to get what I want?
KrLx_roller the much i got is that you want to place text on a button , you do not need to take a septate text view you can add the text like this