0

I am implementing custom listview using Base Adapter after entering the data my list is not refreshed automatically. I need to reopen the fragment to see the update.

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;

}


@Override
public int getCount() {
    return this.leadarrayList.size();
}

@Override
public Object getItem(int position) {
    return leadarrayList.get(position);
}

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

@Override
public 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;
}
Tarun Sharma
  • 914
  • 9
  • 15

4 Answers4

2

after adding your data into the adapter in your fragment do like this

adapter.notifyDataSetChanged();
YuvrajsinhJadeja
  • 1,383
  • 7
  • 23
1

You can call notifyDataSetChanged() when you finishing up adding your data.

Android
  • 11
  • 2
0

When you are adding items into arrayList in your fragment you have to do adapter.notifyDataSetChanged()

0

just notify the list once you done with entering the data, no need to reopen the fragment.

items.clear();
items = db.getItems(); // fetch items from database
listAdapter.notifyDataSetChanged();
Arwy Shelke
  • 333
  • 1
  • 2
  • 12