我需要了解如何从另一个 Activity 调用具有 gridview 的 Activity 。基本上,假设我的主要 Activity 有一个按钮,当您单击该按钮时,您将使用以下示例代码定向到另一个 Activity
public void onClick(View v){
if (v.getId() == R.id.button2) {
Intent intent = new Intent(this, AnotherActivity.class);
this.startActivity(intent);
}
}
但是,如果我被重定向到的 Activity 包含一个 gridview 布局,我该如何在按下按钮时调用它呢?我没有时间在这里写我的代码。如果您只是给我一个想法或制作一个示例代码,那将是最好的。提前致谢。
最佳答案
您的代码应该适用于您拥有的任何 Activity,无论它们的布局如何。只需替换 Intent intent = new Intent(this, AnotherActivity.class);
with Intent intent = new Intent(this, ActivitywithGridView.class);
请记住,如果 GridView 未填充数据,您将看不到它。
关于android - 如何从另一个 Activity 调用 Gridview Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33050043/