I want to disply list of items using Custom ArrayAdapter.
I will insert data by clicking a button.
MainFragment.java
Change your adapter as follows
private class CustomListAdapter extends ArrayAdapter<CustomModel> {
private final Context context;
private final List<CustomModel> list;
private TextView name, message;
public CustomListAdapter(Context context, int resource,
List<CustomModel> list) {
super(context, resource, list);
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.single_row, parent, false);
name = (TextView) view.findViewById(R.id.name);
message = (TextView) view.findViewById(R.id.message);
CustomModel obj = list.get(position);
name.setText(obj.getName());
message.setText(obj.getMessage());
return view;
}
public void updateList(List<CustomModel> list) {
this.list = list;
notifyDataSetChanged();
}
}
so add the method updateList in your adapter itself and call the method notifyDataSetChanged();
so from your activity instead of calling notifyDataSetChanged();
call updateList(List<CustomModel> newList)
I am sure this will work.