I want to work with the selected row of a Table 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 ?
Asked
Active
Viewed 113 times
0

bharath
- 14,283
- 16
- 57
- 95
-
I loop the table components , for (short idxComp=3; idxComp < tList.getComponentCount(); idxComp++) , and I add them focusListener, in the focusGained method I get the selectedRow, and I also execute an action which shows a detail Form of the selected row. Now my problem is when the table Form is shown (first time or back ) then the focus is programatically placed at a certain cell of the table : tList.getComponentAt(c).requestFocus(); and the action of displaying the detail Form I need to be executed is not executed when I click on this cell ! So how to execute the action in this situation ? – Jun 14 '11 at 14:51
1 Answers
1
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);
}
}