我是 android 和 java 的新手,但在我的第一个应用程序中,我正在做 Play 商店,你在 Play 商店看到的第一件事,然后转到第二个活动并在那里看到整个列表。我已经构建了水平 ArrayList 并且我也成功构建GridView了第二个活动,我的 ArrayList 是静态的,我的意思是它没有使用任何服务器。
我的问题是如何MainActivity通过位于其上的适配器将数据发送到MainActivity2.
这是我的主要活动,我的数据位于那里:
public class MainActivity extends AppCompatActivity {
private ArrayList<SectionDataModel> allSampleData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
allSampleData = new ArrayList<>();
RecyclerView recyclerView = findViewById(R.id.my_recycler_view1);
recyclerView.setHasFixedSize(true);
RecyclerViewDataAdapter adapter = new RecyclerViewDataAdapter(allSampleData, this);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
EssentialData();
}
public void EssentialData() {
SectionDataModel Unit1 = new SectionDataModel();
Unit1.setHeaderTitle("Unit 1");
ArrayList<SingleItemModel> singleItemModels = new ArrayList<>();
singleItemModels.add(new SingleItemModel("Word ", "Pronunciation", "Example", R.drawable.alferet));
singleItemModels.add(new SingleItemModel("The Apple", "Apple Store Is Open", "Description book", R.drawable.alferet));
singleItemModels.add(new SingleItemModel("The Apple", "Apple Store Is Open", "Description book", R.drawable.soft));
singleItemModels.add(new SingleItemModel("The Apple", "Apple Store Is Open", "Description book", R.drawable.alferet));
singleItemModels.add(new SingleItemModel("The Apple", "Apple Store Is Open", "Description book", R.drawable.alferet));
singleItemModels.add(new SingleItemModel("The Apple", "Apple Store Is Open", "Description book", R.drawable.alferet));
singleItemModels.add(new SingleItemModel("The Apple", "Apple Store Is Open", "Description book", R.drawable.alferet));
}
}
而我SectionDataAdapter只有从它我可以将数据发送到第二个 MainActivity 因为如果我从MainActivity它自己做它返回 Null
白猪掌柜的
慕沐林林
30秒到达战场
相关分类