Reputation: 492
I have a custom GridView
Adapter
, and showing some images from MySQL
database. How can i show image in Full Screen?
Here is my adapter:
package com.paperless.custom;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.dk.paperless.ProjeDuyurulari;
import com.dk.paperless.R;
public class ProjeAdapter extends BaseAdapter {
private Activity activity;
public ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public ProjeAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.projeduyurugrid, null);
TextView projeIsim= (TextView)vi.findViewById(R.id.projeIsim); // proje ismi
ImageView projeResim = (ImageView)vi.findViewById(R.id.projeResim); // proje resmi
HashMap<String, String> proje = new HashMap<String, String>();
proje = data.get(position);
projeIsim.setText(proje.get(ProjeDuyurulari.TAG_PROJEADI));
imageLoader.DisplayImage(proje.get(ProjeDuyurulari.TAG_FOTOGRAF), projeResim);
return vi;
}
}
And i set it to GridView :
adapter=new ProjeAdapter(ProjeDuyurulari.this, projeList);
grid.setAdapter(adapter);
OnClick Method:
@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
//tried some stuff here like getId()... getId() gives -1 all time time btw.
}
I put the URl in String like this:
String fotograf = c.getString(TAG_FOTOGRAF);
projeduyurugrid:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<ImageView
android:id="@+id/projeResim"
android:layout_width="250dp"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="10dp"
android:contentDescription="@string/projeresmi"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/projeIsim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/projeResim"
android:layout_centerHorizontal="true"
android:layout_marginLeft="79dp"
android:layout_marginTop="53dp"
android:layout_centerInParent="true"
android:text="@string/projeismi"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
Upvotes: 1
Views: 1443
Reputation: 5236
I suppose getting the index of clicked item will be enough
@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
//tried some stuff here like getId()... getId() gives -1 all time time btw.
}
arg2 is the index of clicked item use it to get the URL as : d.get(arg2).get(ProjeDuyurulari.TAG_FOTOGRAF)
and pass it to your new Activity
where you want to display the image full screen
Hope it helps dostum (:
Upvotes: 1
Reputation: 18933
First Make your ArrayList static in which your Image URL saved.
After that use this:
@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {
Intent n = new Intent(SourceActivity.this,yourDesiredActivity.this);
n.putExtra("postition",arg2);
startActivity(n);
}
});
Now in your Desired Activity retrieve
Intent n = getIntent();
int pos = n.getIntExtras("position",0);
urImageview.setImageResource(yourActivity.arraylist[pos]);
Upvotes: 1