Android : Edittext content and checkbox checked change after scrolling

on Saturday, September 20, 2014


I have a ListView that any row have a Checkbox and Edittext. I make a simple adapter and use it for inflate my xml. but after scrolling in listview (if list bigger then one page),the contents of Edittexts and Check mark of Checkboxes change. my adapter is in below .help me friends.



package com.moghaddasan.adinemarket;

import java.util.ArrayList;
import java.util.HashMap;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;

public class BuyProductAdapter extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;

ListView list;
ArrayList<HashMap<String, String>> menuItems;
BuyProductAdapter adapter;

public BuyProductAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
return data.size();
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}

@SuppressLint("InflateParams")
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
View vi=convertView;
if(convertView==null){

vi = inflater.inflate(R.layout.buy_row, null);
holder = new ViewHolder();
holder.mDetailEditText = (EditText)vi.findViewById(R.id.buy_prd_counter);
holder.delChk = (CheckBox)vi.findViewById(R.id.delCheck);
vi.setTag(holder);
}
return vi;
}

static class ViewHolder{
public EditText mDetailEditText;
public CheckBox delChk;
}
}

0 comments:

Post a Comment