1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
public class Morceau_fils extends BaseAdapter implements TextWatcher { // La j'ai du rajouter les 3 méthodes du TextWatcher (ou la déclarer abstract)
private List<Fils> mListF;
private Context mContext;
private LayoutInflater mInflater;
private int mmode;
private SparseArray<String> editedValues;
public Morceau_fils(Context context, List<Fils> aListF, Integer mode) {
mContext = context;
mListF = aListF;
mInflater = LayoutInflater.from(mContext);
mmode = mode;
this.editedValues = new SparseArray<String>();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void afterTextChanged(Editable s) { }
public int getCount() {
return mListF.size();
}
public Object getItem(int position) {
return mListF.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent){
LinearLayout layoutItem;
if (convertView == null) {
layoutItem = (LinearLayout) mInflater.inflate(R.layout.activity_morceau_fils, parent, false);
} else {
layoutItem = (LinearLayout) convertView;
}
TextView tv_Nom = (TextView)layoutItem.findViewById(R.id.TV_mFils_Nom);
final EditText et_Val = (EditText)layoutItem.findViewById(R.id.ET_mFils_Val);
final Switch sw_Bool = (Switch)layoutItem.findViewById(R.id.switch1);
Integer type = mListF.get(position).GetType_fils();
String val = mListF.get(position).GetValeur_fils();
...
String edited = this.editedValues.get(position);
if (edited == null)
et_Val.setText(val);
else
et_Val.setText(edited);
TextWatcher watcher = (TextWatcher) et_Val.getTag();
if (watcher != null)
et_Val.removeTextChangedListener(watcher);
watcher = new ListTextWatcher(position);
et_Val.addTextChangedListener(watcher);
et_Val.setTag(watcher);
return layoutItem;
}
private class ListTextWatcher implements TextWatcher {
int position;
public ListTextWatcher(int p) { this.position = p;}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Morceau_fils.this.editedValues.put(this.position, s.toString());
}
}
} |
Partager