所以我所拥有的是从我的firebase数据库中的图像填充的gridview。我想要做的是能够从gridview中单击其中一个图像并使图像成为整页(具有自己的布局)。所以这是在我的ProfileFragment中,我在ViewPicFragment中设置了完整的照片设置页面。这是我的ProfileFragment中的setUpGridView
private void setupGridView(){
Log.d(TAG, "setupGridView: Setting up image grid.");
final ArrayList<Photo> photos = new ArrayList<>();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference
.child(getString(R.string.dbname_user_photos))
.child(FirebaseAuth.getInstance().getCurrentUser().getUid());
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for ( DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
photos.add(singleSnapshot.getValue(Photo.class));
}
//setup image grid
int gridWidth = getResources().getDisplayMetrics().widthPixels;
int imageWidth = gridWidth/NUM_GRID_COLUMNS;
gridView.setColumnWidth(imageWidth);
ArrayList<String> imgUrls = new ArrayList<String>();
for(int i = 0; i < photos.size(); i++){
imgUrls.add(photos.get(i).getImage_path());
}
GridImageAdapter adapter = new GridImageAdapter(getActivity(),R.layout.layout_grid_imageview,
"", imgUrls);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "onCancelled: query cancelled.");
}
});
}
我现在对onItemClickListener的去向感到茫然。请原谅我,如果一些代码不是最好的,我仍然是Java的新手。如果你们都需要看到更多的代码,我很乐意发布更多。只是认为这是必要的代码。