Android: The contents of the EditText are deleted

0

I'm trying to do a sudoku. When removing the keyboard from the screen or when editing is finished, the contents of the EditText in the Grid are deleted by Adapter .

The code is the following and I do not know what is wrong.

public class SudokuAdapter extends BaseAdapter {
    Context context;
    int sudoku1dimension[];
    LayoutInflater inflter;
public SudokuAdapter(Context applicationContext, int[] sudoku1dimension) {
    this.context = applicationContext;
    this.sudoku1dimension = sudoku1dimension;
    inflter = (LayoutInflater.from(applicationContext));
}

@Override
public int getCount() {
    return sudoku1dimension.length;
}

@Override
public Object getItem(int i) {
   return sudoku1dimension[i];
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public View getView(int i, View v, ViewGroup viewGroup) {
   View view=v;

        if (sudoku1dimension[i]==0){

            view = inflter.inflate(R.layout.emptycell, null);
            EditText edtxt = (EditText) view.findViewById(R.id.SudokuVariableNumber);
            final RelativeLayout rel = (RelativeLayout) view.findViewById(R.id.EmptyCell);

            edtxt.setId(i);

           edtxt.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) {
                        final int position = v.getId();
                       // RelativeLayout rel = (RelativeLayout) v.findViewById(R.id.EmptyCell);
                      rel.setBackgroundResource(R.drawable.cell_shape_focused);
                        //EditText edtxt= (EditText) v.findViewById(R.id.SudokuVariableNumber);
                      //  edtxt.setBackgroundColor(Color.GREEN);

                    }else{

                       // RelativeLayout rel = (RelativeLayout) v.findViewById(R.id.EmptyCell);
                        rel.setBackgroundResource(R.drawable.cell_shape);

                    }
                }});

        }else {
            view = inflter.inflate(R.layout.filledcell, null);
            final TextView txtview = (TextView) view.findViewById(R.id.SudokuNumberFix);
            txtview.setText(Integer.toString(sudoku1dimension[i]));
            txtview.setId(i);
            txtview.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) {
                        final int position = v.getId();

                        txtview.setBackgroundColor(Color.GREEN);
                    }else{

                        txtview.setBackgroundColor(Color.WHITE);

                    }
                }});
        }



    //we need to update adapter once we finish with editing


    return view;
}
    
asked by ogs1017 18.11.2016 в 23:56
source

1 answer

0

In case someone serves him I've fixed it by putting the following two lines on the android manifest:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustPan"
    
answered by 19.11.2016 / 13:33
source