I know it's duplicate question, but I didn't find proper answer. In my custom list-view having a two textview and one Editext, when I inserted a value in edit text and scroll then I loss value of edited text. And when I pass string value for an adapter through list adapter then it will show blank edit text.
Here my Adapter code:
class CreateAdapter extends ArrayAdapter<String> {
String[] strItecode=null;
String[] strItem;
String[] strQuantity,text;
Context context;
int temp;
CreateAdapter(Context context, String[] strItemcode, String[] strItem,
String[] strQauntity) {
super(context, R.layout.create_list_item, R.id.txtItemcode, strItemcode);
this.context = context;
this.strItecode = strItemcode;
this.strItem = strItem;
this.strQuantity = strQauntity;
text= new String[strItem.length];
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
temp=position;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater
.inflate(R.layout.create_list_item, parent, false);
holder.txtItecode = (TextView) convertView
.findViewById(R.id.txtItemcode);
holder.txtItem = (TextView) convertView
.findViewById(R.id.txtItem);
holder.editQuantity = (EditText) convertView
.findViewById(R.id.editcreateQuantity);
holder.editQuantity.setTag(position);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.editQuantity.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
text[temp] = s.toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
holder.txtItecode.setText(strItecode[position]);
holder.txtItem.setText(strItem[position]);
holder.editQuantity.setText(text[temp]);
return convertView;
}
class ViewHolder {
TextView txtItecode;
TextView txtItem;
EditText editQuantity;
}
}
I'm working on it past 3 days, how I can fix this problem?