I'm having a little bit of trouble on implementing a gallery into a Fragment. The gallery I'm trying to put in used to be an Activity but I want it to now be a Fragment since I'm now working on a different project to make my app look more cleaner. I'm getting an error at
gridView.setAdapter(new ImageAdapter(this));
and at
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
I honestly have no idea on how to fix these any help would be awesome sauce
Also, I don't have much experience with Fragments and I'm quite new to it so any details that could help me understand what I'm doing wrong is welcomed!
Here's the Java code:
package info.androidhive.slidingmenu;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class GalleryActivity extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); }
//setContentView(R.layout.gallery_layout);
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle saedInstanceState) {
View rootView = inflater.inflate(R.layout.gallery_layout, parent, false);
GridView gridView = (GridView) rootView.findViewById(R.id.photos);
// Instance of ImageAdapter Class
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new 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("id", position);
startActivity(i);
}
});
}
}