假设您有一个类别活动,您要做的是单击某个项目,然后选择一个项目并将该项目传递给下一个活动名称子类别
当您单击一个项目时 - 与类别相关的子项目将显示在下一个类别中
以下是您如何实现这一目标
在类别活动中
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Category category = categorylist.get(position);
Intent intent = new Intent(this,SubCategoryActivity.class);
intent.putExtra("CategoryID",String.valueOf(category.getCategoryid()));
startActivity(intent);
}
现在,当单击一个项目时,它将被选中,然后我们使用 activity.putextra 将其 id 转发到下一个活动
并启动该活动
在下一个活动中,我们将捕获这个元素
protected void onCreate(Bundle savedInstanceState) {
//CREATE AND INFLATE THE VIEW
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subcategory);
//GET THE INTENT AND CATEGORYID
Intent intent = getIntent();
String CategoryID = intent.getStringExtra("CategoryID");
}
现在我们有了这个 categoryid - 现在您可以使用这个 id 进行查询并显示结果
当您单击类别活动中的任何项目时 - 下一个活动将启动并显示结果