How do i make my Gridview clickable



I have this gridview and i want it to start seperate activities once they are clicked. For example my GridView has name and image of Theaters. So once i click a particular theater shown in the gridview it should redirect and show details of that theater. How can i achieve this?


TheaterFragment class



package com.fortuna.cinemalk;

import java.util.ArrayList;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.fortuna.cinemalk.adapter.LazyAdapter;
import com.fortuna.cinemalk.model.BaseElement;
import com.fortuna.cinemalk.service.CommonVariable;
import com.fortuna.cinemalk.service.JSONServices;
import com.fortuna.cinemalk.util.Element;

public class TheaterFragment extends Fragment {

private GridView gridView;

private ArrayList<BaseElement> filmTheater;
private LazyAdapter adapter;
private Activity activity;
private CommonVariable commonVariable;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.theater_fragment, container,
false);

activity = this.getActivity();

commonVariable = (CommonVariable) activity.getApplication();

gridView = (GridView) view.findViewById(R.id.gridView1);

new BackGround().execute();

return view;
}

public class BackGround extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {

filmTheater = JSONServices.getTheater();
return null;
}

@Override
/* check again */
protected void onPostExecute(Void result) {

commonVariable.setTheater(filmTheater);

adapter = new LazyAdapter(filmTheater, activity,
Element.THEATER_LIST.getType());

gridView.setAdapter(adapter);

super.onPostExecute(result);
}

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}

}

}


theater_fragment.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:gravity="center"
android:numColumns="2"
android:stretchMode="columnWidth"
android:layout_margin="5dp"
android:columnWidth="100dp"/>

</LinearLayout>


theater_list_layout



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >



<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"

android:background="@color/tabDark"
android:gravity="center"




/>

<TextView
android:id="@+id/theaters"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:textColor="#ffffff"
android:background="@color/tabDark"
android:textStyle="bold" />



</RelativeLayout>

No comments:

Post a Comment