Question

I have implemented a Expandable ListView In android, in which I am populating a list of EditText boxes in one section of list view. I am entering values in the EditText boxes, it takes values in correct manner. But the problem is that when I enter value in the last EditText box in the list then its value is copied to the first EditText box.

I observed one behavior, when I enter the value in last EditText box and press back button then focus goes to the first EditText box in the list and the value of Laste EditText box is copied to the First EditText box when I scroll up or scroll down in the view.

Dont know what is happening?

holder.editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (!hasFocus) {
            Position position = (Position) v.findViewById(R.id.editTextField).getTag();                     
            if (res != null) {
                res.Value = ((EditText) v).getText().toString();
                Toast.makeText(mContext, res.Value,Toast.LENGTH_SHORT).show();
                setEditTextResult(res);
            }
        }
    }
});
Was it helpful?

Solution

I got the answer for this.

I have to write the code in this way that after pressing back button, edit text will be gone out of focus. The code will differ according to the implementation that is why I am not providing the coding solution. You just need to take care if your EditText box asks for focus somewhere else in your code. Which sometimes cause this bug. You will find that this bug of android in which its adapter only keeps the current items of the view in the memory; causes the bugs with values being removed from the EditText boxes and values being copied to other EditText boxes.

ALl you need is to take care if your EditText boxes are somewhere else requesting for the focus - this is the key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top