2016-06-14 177 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我會用它感謝您的建議 –