我想从两个活动类中获取数据并将它们连接起来进行片段搜索过滤。
在CoinActivity和CoinActiviy2课程中,我有这样的数据
public ArrayList<Coin> getOnecoin()
{
ArrayList<Coin> coins = new ArrayList<>();
Coin coadd = new Coin();
coadd.setCoinid("0008");
coadd.setCoinimages(R.drawable.noimage);
coadd.setDenom("1");
coadd.setYear("1701");
coadd.setMints(this.getResources().getString(R.string.modelmint));
coadd.setMarks("n/a");
coadd.setVariety(this.getResources().getString(R.string.var1));
coadd.setMintages("n/a");
coadd.setObverses(this.getResources().getString(R.string.bust1));
coins.add(coadd);
return coins;
}
我尝试在片段中通过此代码加入它们,但是当我在搜索过滤器中使用getAll()时,它会出现错误。该应用程序无法打开。
public ArrayList<Coin> getAll(){
ArrayList<Coin> list = new ArrayList<>();
CoinActivity yourObject = new CoinActivity();
CoinActivity2 anotherObject = new CoinActivity2();
list.addAll(yourObject.getOnecoin());
list.addAll(anotherObject.getTwocoin());
return list;
}