我想这是在GridView中的图像应在众目睽睽之下展示这是、我想、众目睽睽、应在

2023-09-06 09:33:03 作者:羁绊

全部活动课,其中我想全屏显示图像。我有一个显示在GridView它的所有图像。我不是在这所面临的问题,但是当我点击GridView中的形象它为我作我召刚XML文件。我想我做错了的地方在这里呼吁中的id FullImageAcitivity文件。

 公共类FullImageActivity延伸活动{按钮,下载,setas;@覆盖公共无效的onCreate(捆绑savedInstanceState){    super.onCreate(savedInstanceState);    的setContentView(R.layout.full_image);    setas =(按钮)findViewById(R.id.setas);    下载=(按钮)findViewById(R.id.download);    最终意图I = getIntent();    最终名单<项目>项目=新的ArrayList<项目>();    最后ImageAdapter imageAdapter =新ImageAdapter(本);    ImageView的ImageView的=(ImageView的)findViewById(R.id.full_image_view);    imageView.setImageResource(items.indexOf(I));    setas.setOnClickListener(新OnClickListener(){        @覆盖        公共无效的onClick(视图v){            // TODO自动生成方法存根             WallpaperManager myWallpaperManager             = WallpaperManager.getInstance(getApplicationContext());            尝试{                myWallpaperManager.setResource(imageAdapter.items.indexOf(I));            }赶上(例外五){             // TODO自动生成catch块             e.printStackTrace();            }    }    });  }} 

这是我的imageAdapter文件。

 公共类ImageAdapter延伸BaseAdapter {清单<项目>项目=新的ArrayList<项目>();私人LayoutInflater吹气;公共ImageAdapter(上下文的背景下){    充气= LayoutInflater.from(上下文);    items.add(新项目(一,R.drawable.abstact_one));    items.add(新项目(二,R.drawable.abstract_three));    items.add(新项目(三公,R.drawable.image_two));    items.add(新项目(四,R.drawable.image_four));    items.add(新项目(十二五,R.drawable.image_five));    items.add(新项目(六个一,R.drawable.image_nine));    items.add(新项目(七宗罪,R.drawable.image_ten));}@覆盖公众诠释的getCount(){    返回items.size();}@覆盖公共对象的getItem(int i)以{    返回items.get(ⅰ);}@覆盖众长getItemId(int i)以{    返回items.get(我).drawableId;}@覆盖公共查看getView(INT I,观景,ViewGroup中的ViewGroup){    视图V =视图。    ImageView的图片;    TextView的名称;    如果(V == NULL){        V = inflater.inflate(R.layout.other,ViewGroup中,FALSE);        v.setTag(R.id.picture,v.findViewById(R.id.picture));        v.setTag(R.id.text,v.findViewById(R.id.text));    }    照片=(ImageView的)v.getTag(R.id.picture);    名称=(TextView中)v.getTag(R.id.text);    项目项目=(项目)的getItem(I)    picture.setImageResource(item.drawableId);    name.setText(item.name);    返回伏;}私有类项目{    最终字符串名称;    最终诠释drawableId;    项目(字符串名称,诠释drawableId){        this.name =名称;        this.drawableId = drawableId;    } }} 

latestTab活动文件

 公共类LatestTab延伸活动{@覆盖公共无效的onCreate(捆绑savedInstanceState){      super.onCreate(savedInstanceState);      的setContentView(R.layout.latestphotos);      GridView控件的GridView =(GridView控件)findViewById(R.id.grid_view);        // ImageAdapter类的实例        gridView.setAdapter(新ImageAdapter(本));        / **         *在单人项目的GridView Click事件         * * /        gridView.setOnItemClickListener(新OnItemClickListener(){            @覆盖            公共无效onItemClick(适配器视图<>母公司,视图V,                    INT位置,长的id){                //发送图片ID来FullScreenActivity                意图I =新意图(getApplicationContext(),FullImageActivity.class);                //传递数组索引                i.putExtra(ID,位置);                startActivity(ⅰ);            }        });}} 
asp.net 图片地址列的数据是有两张图片地址,读出数据后,怎么在GridView中显示图片列中的两张图片

full_image.xml

 <?XML版本=1.0编码=UTF-8&GT?;< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:layout_width =match_parent机器人:layout_height =match_parent机器人:方向=垂直>< RelativeLayout的    机器人:ID =@ + ID / relshare    机器人:layout_width =FILL_PARENT    机器人:layout_height =WRAP_CONTENT    机器人:layout_alignParentTop =真    机器人:背景=#79B8B8B8>    <按钮        机器人:ID =@ + ID / setas        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_alignParentTop =真        机器人:layout_marginLeft =14dp        机器人:layout_toRightOf =@ + ID /股        机器人:重力=右        机器人:文字=设置为        机器人:TEXTSIZE =25sp/>    <按钮        机器人:ID =@ + ID /下载        机器人:layout_width =WRAP_CONTENT        机器人:layout_height =WRAP_CONTENT        机器人:layout_alignParentRight =真        机器人:layout_alignParentTop =真        机器人:layout_marginRight =34dp        机器人:文字=下载        机器人:TEXTSIZE =25sp/>< / RelativeLayout的>< ImageView的机器人:ID =@ + ID / full_image_view        机器人:layout_width =FILL_PARENT        机器人:layout_height =FILL_PARENT/>< / LinearLayout中> 

latestphotos.xml

 <?XML版本=1.0编码=UTF-8&GT?;<的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android机器人:layout_width =match_parent机器人:layout_height =match_parent>< GridView控件    机器人:ID =@ + ID / grid_view    机器人:layout_width =match_parent    机器人:layout_height =match_parent    机器人:verticalSpacing =0dp    机器人:horizo​​ntalSpacing =0dp    机器人:stretchMode =columnWidth时    机器人:为numColumns =2    />< /&的FrameLayout GT; 

解决方案

在你的 LatestTab

声明列表作为一个类成员

 列表<项目>项目=新的ArrayList<项目>(); 

添加项目到列表中。

  items.add(新项目(一,R.drawable.abstact_one));items.add(新项目(二,R.drawable.abstract_three));items.add(新项目(三公,R.drawable.image_two));items.add(新项目(四,R.drawable.image_four));items.add(新项目(十二五,R.drawable.image_five));items.add(新项目(六个一,R.drawable.image_nine));items.add(新项目(七宗罪,R.drawable.image_ten)); 

您Item类

 公共类项目{字符串名称;INT绘制;公众诠释getDrawable(){    返回绘制;}公共无效setDrawable(INT绘制){    this.drawable =绘制;}公共项目(字符串名称,诠释ID){    this.name =名称;    this.drawable = ID;}公共字符串的getName(){    返回名称;}公共无效setname可以(字符串名称){    this.name =名称;}} 

通过列表适配器类的构造函数

  gridView.setAdapter(新ImageAdapter(这一点,项目)); 

在构造

 列表<项目>项目;  公共ImageAdapter(上下文的背景下,列表与LT;项目>项目){   充气= LayoutInflater.from(上下文);   this.items =物品; } 

然后getVIew

 项目项=(项目)items.get(I) picture.setImageResource(item.getDrawable()); 

然后在项目点击监听器

 项项= items.get(位置);  INT ID = item.getDrawable();  意图I =新意图(getApplicationContext(),FullImageActivity.class);  i.putExtra(idkey,ID); //通过ID  startActivity(ⅰ); 

然后在FullImageActivity

  INT ID = getIntent()getIntExtra(idkey); //获取ID  imageview.setImageResource(ID); //设置绘制到ImageView的 

Full Activity Class where the I want to display the Image in full Screen. I have all the images showing it in the gridView. I am not facing problem in that, however when I click on the image of the gridview it shows me the just the xml file which I have called. I guess I am doing wrong somewhere calling the id here in the FullImageAcitivity file.

public class FullImageActivity extends Activity {

Button download, setas;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);
    setas = (Button) findViewById(R.id.setas);
    download = (Button)findViewById(R.id.download);
    final Intent i = getIntent();
    final   List<Item> items = new ArrayList<Item>();
    final ImageAdapter imageAdapter = new ImageAdapter(this);       
    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
    imageView.setImageResource(items.indexOf(i));
    setas.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             WallpaperManager myWallpaperManager
             = WallpaperManager.getInstance(getApplicationContext());
            try {
                myWallpaperManager.setResource(imageAdapter.items.indexOf(i));
            } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
    }
    });
  }
}

here is my imageAdapter file.

public class ImageAdapter extends BaseAdapter {
List<Item> items = new ArrayList<Item>();
private LayoutInflater inflater;

public ImageAdapter(Context context) {
    inflater = LayoutInflater.from(context);

    items.add(new Item("One",       R.drawable.abstact_one));
    items.add(new Item("Two",   R.drawable.abstract_three));
    items.add(new Item("Three", R.drawable.image_two));
    items.add(new Item("Four",      R.drawable.image_four));
    items.add(new Item("Five",     R.drawable.image_five));
    items.add(new Item("Six",      R.drawable.image_nine));
    items.add(new Item("Seven",       R.drawable.image_ten));
}

@Override
public int getCount() {
    return items.size();
}

@Override
public Object getItem(int i) {
    return items.get(i);
}

@Override
public long getItemId(int i) {
    return items.get(i).drawableId;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    View v = view;
    ImageView picture;
    TextView name;

    if(v == null) {
        v = inflater.inflate(R.layout.other, viewGroup, false);
        v.setTag(R.id.picture, v.findViewById(R.id.picture));
        v.setTag(R.id.text, v.findViewById(R.id.text));
    }

    picture = (ImageView)v.getTag(R.id.picture);
    name = (TextView)v.getTag(R.id.text);

    Item item = (Item)getItem(i);

    picture.setImageResource(item.drawableId);
    name.setText(item.name);

    return v;
}

private class Item {
    final String name;
    final int drawableId;

    Item(String name, int drawableId) {
        this.name = name;
        this.drawableId = drawableId;
    }
 }
}

latestTab Activity File

public class LatestTab extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.latestphotos);

      GridView gridView = (GridView) findViewById(R.id.grid_view);

        // Instance of ImageAdapter Class
        gridView.setAdapter(new ImageAdapter(this));

        /**
         * On Click event for Single Gridview Item
         * */
        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);
            }
        });

}
}

full_image.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/relshare"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="#79B8B8B8" >

    <Button
        android:id="@+id/setas"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="14dp"
        android:layout_toRightOf="@+id/share"
        android:gravity="right"
        android:text="Set As"
        android:textSize="25sp" />

    <Button
        android:id="@+id/download"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="34dp"
        android:text="Download"
        android:textSize="25sp" />

</RelativeLayout>

<ImageView android:id="@+id/full_image_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

</LinearLayout>

latestphotos.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
    android:id="@+id/grid_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:stretchMode="columnWidth"
    android:numColumns="2" 
    />
</FrameLayout>

解决方案

In your LatestTab

Declare the list as a class member

  List<Item> items = new ArrayList<Item>();

Add the items to the list

items.add(new Item("One", R.drawable.abstact_one));
items.add(new Item("Two",  R.drawable.abstract_three));
items.add(new Item("Three", R.drawable.image_two));
items.add(new Item("Four", R.drawable.image_four));
items.add(new Item("Five", R.drawable.image_five));
items.add(new Item("Six",  R.drawable.image_nine));
items.add(new Item("Seven", R.drawable.image_ten));

Your Item class

public class Item {
String name;
int drawable;
public int getDrawable() {
    return drawable;
}
public void setDrawable(int drawable) {
    this.drawable = drawable;
}
public Item(String name, int id)
{
    this.name= name;
    this.drawable = id;
}
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

Pass the list to the constructor of adapter class

 gridView.setAdapter(new ImageAdapter(this,items));

In the constructor

  List<Item> items;
  public ImageAdapter(Context context,List<Item> items) {
   inflater = LayoutInflater.from(context);
   this.items = items;
 } 

then in getVIew

 Item item = (Item)items.get(i);
 picture.setImageResource(item.getDrawable());

Then in item click listener

  Item item = items.get(position);
  int  id = item.getDrawable(); 
  Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
  i.putExtra("idkey", id); // pass the id
  startActivity(i);

Then in FullImageActivity

  int id = getIntent().getIntExtra("idkey"); //get id
  imageview.setImageResource(id); // set the drawable to imageview