如何从另一个活动调用GridView的活动GridView

2023-09-12 05:38:16 作者:爷丶拽的有特点

我需要如何调用具有从另一个活动一个gridview的活动的想法。基本上,我认为主要活动有一个按钮,当你点击该按钮将被定向到与下面的示例code另一个活动

I need an idea on how to call an activity that has a gridview from another activity. Basically, supposed my main activity has one button and when you click the button you are directed to another activity with the following sample code

 public void onClick(View v){
 if (v.getId() == R.id.button2) {
        Intent intent = new Intent(this, AnotherActivity.class);
        this.startActivity(intent);

    }
 }

但是,如果我被重定向到活动包含一个gridview布局,我怎么叫,当我preSS的按钮?我没有时间在这里写我的code。这将是最好的,如果你只是给我一个想法或做出样品code预先感谢。

But what if the activity that I'm being redirected to contains a gridview layout, how do I call that when I press the button? I don't have time to write my code here. It would be best if you just give me an idea or make a sample code thanks in advance.

推荐答案

您需要调用 ActivityName.this ,而不是这。

而不是使用你可以使用 ActivityName.this ,它可以让你的活动。目前,是给你的的onClick()方法方面的参考。

Instead of using this you could use ActivityName.this, it gets you the context of the Activity. Currently this is giving you onClick() method context reference.

问题是适当的范围内不流通所以它不是首发活动。

Issue is Proper context is not passing so its not starting Activity.

您可以试试这个code。

You can try this code.

public void onClick(View v){
 if (v.getId() == R.id.button2) {
        Intent intent = new Intent(ActivityName.this, GridViewActivity.class);
        ActivityName.this.startActivity(intent);
    }
}
 
精彩推荐