I want to work with the selected row of a Tab开发者_C百科le when the device is a touch one in the pointerPressed
method , and what I get is a wrong value : for example I clicked the third line ( PS : the header line is -1 ) and I got 0 as a value in the System.out.println
! And when I click another row then I get the row I selected before !
So how to synchronize LWUIT with the selected row ?
Ok , I found the solution : in the constructor I wrote :
for (short idxComp=3; idxComp<tList.getComponentCount(); idxComp++)
{
tList.getComponentAt(idxComp).addFocusListener(this);
}
isTableSelected = false;
And here are the implemented methods :
public void pointerPressed(int x, int y)
{
int startX, startY, endX, endY, nbComps;
nbComps = tList.getComponentCount();
startX = tList.getComponentAt(3).getAbsoluteX();
endX = tList.getComponentAt(5).getAbsoluteX() + tList.getComponentAt(5).getWidth();
startY = tList.getComponentAt(3).getAbsoluteY();
endY = tList.getComponentAt(nbComps-1).getAbsoluteY() + tList.getComponentAt(nbComps-1).getHeight();
if ( (x >= startX && x <= endX) && (y >= startY && y <= endY) )
{
isTableSelected = true;
if ( (x >= selectedComp.getAbsoluteX() && x <= (selectedComp.getAbsoluteX()+selectedComp.getWidth())) && (y >= selectedComp.getAbsoluteY() && y <= (selectedComp.getAbsoluteY()+selectedComp.getHeight())) )
afficheFicheCredit(selectedRow);
}
}
public void focusGained(Component comp) {
tList.repaint();
selectedComp = tList.getComponentAt(3*selectedRow+3);
if (isTableSelected)
{
isTableSelected = false;
selectedRow = tList.getSelectedRow();
afficheFicheCredit(selectedRow);
}
}
精彩评论