2016-06-14 111 views
0

我一直在使用简单的适配器列表视图和我有问题,尽管调用adapter.notifyDataSetChanged()我的列表视图没有得到更新;所以它在简单的适配器中工作?下面是我的简单适配器的代码。 我宣布简单的适配器全球listview没有得到更新

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(); 
+0

调用'adapter.notifyDataSetChanged();'在将其设置为列表视图之前 – SripadRaj

+0

@Enlightened如何获取'SimpleAdapter'内的arrayList?您是在创建新对象还是仅仅引用? – Godather

+0

调用adapter.notifyDataSetChanged()方法没有意义。紧接着设置适配器后。发布SimpleAdapter类。 –

回答

0

我已经解决了它,我已经创建了单独的类适配器和我已经BaseAdapter延长,使下面是我的代码

公共类SurgeryAdapter延伸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; 
} 

}

我称adapter.notifyDataSetChanged();在我的片段之前设置适配器到列表视图

+0

你好Lakshman请使用pojo类的有效代码 –

+0

k mahadev我会用它感谢您的建议 –