Android在FullScreen中从GridView显示来自URL的图像

时间:2014-01-04 14:33:21

标签: android gridview

我有自定义GridView Adapter,并显示MySQL数据库中的一些图片。如何在全屏中显示图像?

这是我的适配器:

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;
    }
}

我把它设置为GridView:

adapter=new ProjeAdapter(ProjeDuyurulari.this, projeList); 
grid.setAdapter(adapter);

OnClick方法:

@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.
}

我把URl放在String中就像这样:

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>

2 个答案:

答案 0 :(得分:1)

我认为获得点击项目的索引就足够了

@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 是点击项目的索引,使用它来获取网址d.get(arg2).get(ProjeDuyurulari.TAG_FOTOGRAF)并将其传递给您新的Activity想要全屏显示图像

希望它有助于dostum(:

答案 1 :(得分:1)

首先制作保存图片网址的 ArrayList 静态

之后使用它:

@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);  
    }
  });

现在在您想要的活动检索中

 Intent n = getIntent();

 int pos = n.getIntExtras("position",0);

 urImageview.setImageResource(yourActivity.arraylist[pos]);