Enlightened Enlightened - 5 months ago 22
Android Question

listview not getting update

I have been using simple adapter listview and I having problem that my listview not getting update despite calling adapter.notifyDataSetChanged(); so is it working in simple adapter? below is my code for simple adapter.
I have declared simple adapter globally

adapter = new SimpleAdapter(
getActivity(), ssLst,
R.layout.surgerysch_item, new String[]{
TAG_SIMRDNO, TAG_SIPNME, TAG_SISEX,
TAG_SIDOB, TAG_SIPROC, TAG_SIOTNME,
TAG_SIOTME, TAG_DRNAME}, new int[]{R.id.txtsimrdNo,
R.id.txtsiptnNme, R.id.txtsiSex,
R.id.txtsiDob, R.id.txtsiProc,
R.id.txtsiotNme, R.id.txtsiotTme, R.id.txtDrnme});

lstViw.setAdapter(adapter);
adapter.notifyDataSetChanged();

Answer

I have solved it for that I have created separate class for adapter and I have extended by BaseAdapter so following is my code

public class SurgeryAdapter extends BaseAdapter {

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

public SurgeryAdapter(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;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.surgerysch_item, null);

    TextView txt_Mrdno = (TextView) vi.findViewById(R.id.txtsimrdNo);
    TextView txt_Ptnnme = (TextView) vi.findViewById(R.id.txtsiptnNme);
    TextView txt_Sex = (TextView) vi.findViewById(R.id.txtsiSex);
    TextView txt_Dob = (TextView) vi.findViewById(R.id.txtsiDob);
    TextView txt_Proce = (TextView) vi.findViewById(R.id.txtsiProc);
    TextView txt_Otnme = (TextView) vi.findViewById(R.id.txtsiotNme);
    TextView txt_Ottme = (TextView) vi.findViewById(R.id.txtsiotTme);
    TextView txtdrNme = (TextView) vi.findViewById(R.id.txtDrnme);
    TextView txtanstetic = (TextView) vi.findViewById(R.id.txtAnesthestist);


    HashMap<String, String> item = new HashMap<String, String>();
    item = data.get(position);

    //Setting all values in listview
    txt_Mrdno.setText(item.get("mrd_no"));
    txt_Ptnnme.setText(item.get("pname"));
    txt_Sex.setText(item.get("sex"));
    txt_Dob.setText(item.get("dob"));
    txt_Proce.setText(item.get("procedure"));
    txt_Otnme.setText(item.get("otName"));
    txt_Ottme.setText(item.get("otTime"));
    txtdrNme.setText(item.get("docName"));
    txtanstetic.setText(item.get("anesthetists"));
    return vi;
}

}

I have called adapter.notifyDataSetChanged(); in my fragment before setting adapter to listview

Comments