I'm trying to make an android app using gridview(http://www.rogcg.com/blog/2013/11/01/gridview-with-auto-resized-images-on-android) and mediaplayer(http://examples.javacodegeeks.com/android/android-mediaplayer-example/) trying to combine the two tutorials I found so it would be possible to select an image from GridView acitivity launching a MediaPlayer activity that would play a song.
GridView tutorial suggested this to enable the clicking:
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
// this 'mActivity' parameter is Activity object, you can send the current activity.
Intent i = new Intent(MainActivity.this, AndroidMediaPlayer.class);
MainActivity.startActivity(i);
}
});
But I could not get it to work out and got warning:
Non-static method 'startActivity(android.content.Intent)' cannot be referenced from a static context
v.getContext().startActivity(i);
Get context from your view before calling startActivity or use global context According to your tutorial you adapter class placed in MainActivity.class Thats why you also can use next type of calling
MainActivity.this.startActivity(i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With