Shikhar13 / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

DataChangedListener for TextField does not work in Android #297

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The following issue occurs on Android phones.

I've implemented a search functionality where a component (namely a long list) 
would update as user enters text into a search box.  However, the code that 
used to work in LWUIT does not work in CodenameOne.

I've implemented a small sample to test what's happening.

public class TestDataChangeScreen extends Form implements ActionListener, 
DataChangedListener {

    private Form mPrev;
    private Command mBackCmd = new Command("Back");

    private TextField mSearchField;
    private Label mSearchString;

    public TestDataChangeScreen(Form prev) {
        this.setTitle("Main Screen");

        mPrev = prev;

        addCommand(mBackCmd);
        this.addCommandListener(this);
        this.setBackCommand(mBackCmd);

        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        mSearchField = new TextField();
        mSearchField.addDataChangeListener(this);

        addComponent(mSearchField);

        mSearchString = new Label("----------");
        addComponent(mSearchString);
    }

    @Override
    public void dataChanged(int type, int index) {
        System.out.println("SCB: data changed type=" + type + " index=" + index + " text=" + mSearchField.getText());
        mSearchString.setText(mSearchField.getText());
    }

    @Override
    public void actionPerformed(ActionEvent evt) {
        if (evt.getSource() == mBackCmd) {
            evt.consume();

            if (mPrev != null) {
                mPrev.showBack();
            }
        }
    }
}

The problem is that as I enter text into the mSearchField the dataChanged 
method gets called, but the arguments are always the same:  type=2 (CHANGED) 
index=-1, mSearchField.getText() returns an empty string even so there may be 
some characters displayed.

Original issue reported on code.google.com by gt88...@gmail.com on 17 Aug 2012 at 7:10

GoogleCodeExporter commented 9 years ago
This is probably due to the patch for text of the native edit view appearing on 
top of the lightweight text field. 

Original comment by shai.almog on 18 Aug 2012 at 3:27

GoogleCodeExporter commented 9 years ago
fixed, thanks

Original comment by cf27...@gmail.com on 30 Aug 2012 at 7:30