5,380 questions
How can l update a list on oncreate with a method ?
Hi, YusufAtasever. Could you post more details about the requirement? Do you mean updating the listView? If so, change the data list and then call the NotifyDataSetChanged command.
public class MainActivity : AppCompatActivity
{
List<CustomModel> list;
CustomAdapter adapter;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
list = new List<CustomModel>();
adapter = new CustomAdapter(list);
ListView listView = FindViewById<ListView>(Resource.Id.listview_);
listView.SetAdapter(adapter);
var btn = FindViewById<Button>(Resource.Id.btn);
btn.Click += Btn_Click;
}
private void Btn_Click(object sender, EventArgs e)
{
list.Add(xx);
adapter.NotifyDataSetChanged();
}
}