我想在插入新数据后更新列表视图。
使用主(主要活动)界面进行更新时,该过程执行得很好。从第一个接口调用更新到第二个(SecondActivity)接口时,更新不会更新。更新第二个(SecondActivity)接口有什么问题?
//main activity update work well
public ListView listtable;
public ArrayAdapter<string> adapter;
public static List<string> Original;
//update
fillarray();
adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, Original);
listtable.Adapter = adapter;
//SecondActivity not work
MainActivity sqldbc = new MainActivity();
sqldbc.fillarray();
sqldbc.adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, MainActivity.Original);
sqldbc.listtable.Adapter = sqldbc.adapter;
Mainactivity.cs:
public static ListView listview1;
public static List<string> list;
//insert data into db method.
adddata();
listview1.Adapter = new ArrayAdapter(this,Android.Resource.Layout.SimpleListItem1, list);
SecondActivity.cs:
private MainActivity mactivity;
mactivity = new MainActivity();
mactivity.adddata();
MainActivity.listview1.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, MainActivity.list);
返回时,可以看到ListView数据更新。