输入数据后,我正在使用基本适配器实现自定义列表视图,我的列表不会自动刷新。我需要重新打开片段才能看到更新。public class Lead_Adapter extends BaseAdapter {private Context context;private ArrayList<Lead_Model> leadarrayList;public Lead_Adapter(Context context,ArrayList<Lead_Model>arrayList){ this.context = context; this.leadarrayList = arrayList;}@Overridepublic int getCount() { return this.leadarrayList.size();}@Overridepublic Object getItem(int position) { return leadarrayList.get(position);}@Overridepublic long getItemId(int position) { return position;}@Overridepublic View getView(int position, View convert_view, ViewGroup parent) { LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convert_view = layoutInflater.inflate(R.layout.lead_listview, null); TextView Company_Name = convert_view.findViewById(R.id.company_name_listview); TextView Lead_Status = convert_view.findViewById(R.id.lead_status_listview); TextView Lead_Date = convert_view.findViewById(R.id.lead_date_listview); Lead_Model leadModel = leadarrayList.get(position); Company_Name.setText(leadModel.getCompany_name()); Lead_Status.setText(leadModel.getLead_status()); Lead_Date.setText(leadModel.getDate()); return convert_view;}
4 回答
狐的传说
TA贡献1804条经验 获得超3个赞
输入数据完成后只需通知列表即可,无需重新打开片段。
items.clear();
items = db.getItems(); // fetch items from database
listAdapter.notifyDataSetChanged();
添加回答
举报
0/150
提交
取消