Estoy intentando hacer un sudoku. Al sacar el teclado de la pantalla o al acabar la edición se borra el contenido de los EditText
que hay en el Grid
mediante el Adapter
.
El código es el siguiente y no se lo que esta mal.
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;
}
}