package com.androidcreation.gridview;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
public class MainActivity extends AppCompatActivity {
Integer images[]={R.drawable.actress,R.drawable.robert,R.drawable.angelina,R.drawable.chris,R.drawable.cute,
R.drawable.deepika,R.drawable.jony,R.drawable.scrollet,R.drawable.dwaynejohnson,R.drawable.leonardo,R.drawable.tom,
R.drawable.kristian,R.drawable.actress2,R.drawable.actress3,R.drawable.actress4};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = findViewById(R.id.gridView);
// Instance of ImageAdapter Class
final ImageAdapter imageAdapter= new ImageAdapter(this,images);
gridView.setAdapter(imageAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
i.putExtra("image", images[position]);
startActivity(i);
}
});
}
}
1 Comment
Androidena
Create a new android application using android studio and give names as GridView. In case if you are not aware of creating an app in android studio check this article Android Hello World App .