2014-12-24 46 views
0

所以我有一个回收站视图适配器在我的MainActivity中设置。该适配器连接到我称为组的自定义对象的数组列表。回收站视图适配器没有反映变化

public static RecyclerView.Adapter groupsListAdapter; 
public ArrayList<Group> myGroups; 

//内主要的活性的onCreate

groupsListAdapter = new MyAdapter(myGroups); 

在一个不同的活动,我将其通过的意图更新此数组列表的内容,第一。

Intent groupCreationIntent = new Intent(MainActivity.this, NewGroupActivity.class); 
     groupCreationIntent.putExtra("groupsList",myGroups); 
     startActivity(groupCreationIntent); 

然后在其他活动中更新它。

private ArrayList<Group> groups; 

//在其他活动的onCreate方法

groups = (ArrayList<Group>) getIntent().getSerializableExtra("groupsList"); 

当回到以前的活动(第二个活动是用于输入一些信息,并与我的数据库同步的话)我运行此代码。

​​

问题是列表适配器没有反映更改,一旦我返回到主要活动,没有任何内容出现在我的列表中。我究竟做错了什么?

+0

如果数组列表得到填充,那么在获得结果后,如果在主要活动上做了notifydataset更改的最后部分,那将会更好。 – Ahmed

+0

你检查了notifydatasetchange()没有反映变化的其他职位? – Elltz

回答

1
class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { 

    private List<Group> items; 

    public MyAdapter(List<Group> items) { 
    this.items = items; 
    } 

    // .. your implementation 

    // add and call this 
    public void add(Group item) { 
    this.items.add(item); 
    notifyItemInserted(items.size() - 1); 
    } 
} 

它与您的问题没有关系,您不应该使用静态字段进行活动与活动的交流。

相关问题